Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Fri, 16 Jan 2004 21:08:03 -0500 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: Problem using kill for child process Message-ID: <20040117020803.GA6090@redhat.com> Mail-Followup-To: cygwin AT cygwin DOT com References: <20040117011732 DOT 53374 DOT qmail AT web20305 DOT mail DOT yahoo DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040117011732.53374.qmail@web20305.mail.yahoo.com> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com 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 >#include >#include >#include >#include > >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 #include 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/