Mail Archives: cygwin/2004/01/16/21:08:05
On Sat, Jan 17, 2004 at 02:17:32AM +0100, Pierre Mallard wrote:
>If I call from my parent process a simple kill(pid)
>then it doesn't stop the child process at all, or
>maybe after more than one minute but I don't think
>so...
>If I send from my parent process a kill(pid,x) where x
>is 1 or 9, then when I wait after in parent for child
>termination with waitfunction I have a segmentation
>fault during wait...
>PS if parent is killed with Ctrl-C, I can kill child
>then from shell with kill pid
>Thanks for your help
>Pierre
>
>#include <unistd.h>
>#include <sys\types.h>
>#include <stdio.h>
>#include <stdlib.h>
>#include <time.h>
>
>int main(int argc,char ** argv){
>
>pid_t pid;
>int times = 10;
>int i;
>
>pid=fork();
>if (pid < 0){
> return 1;
>}
>else if (pid == 0){ //Child
> while(1){
> sleep(5);
> printf("Child\n");fflush(stdout);
> }
> return 0;
>}
>else{//Parent
> for(i=1;i<=times;i++){
> sleep(1);
> printf("Parent\n");fflush(stdout);
> }
> printf("Killing Child (pid %d)\n",pid);
> kill(pid); //Or kill(pid,1)
> printf("Waiting for child to terminate\n");
> wait(); //Seg Fault if kill(pid,1)
> //Wait till tomorrow if kill(pid)
> printf("Exiting\n");fflush(stdout);
> return 0;
>}
>}
Try adding a
#include <wait.h>
#include <signal.h>
to your program and then correcting the subsequent error messages.
The arguments to kill and wait are not optional.
cgf
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -