This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem using kill for child process


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]