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: Wed, 17 Dec 2003 12:27:28 -0500 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: kill(pid, 0) issue Message-ID: <20031217172728.GB12975@redhat.com> Mail-Followup-To: cygwin AT cygwin DOT com References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com On Wed, Dec 17, 2003 at 05:23:20PM +0100, Nowakowski Maciej-AMN011 wrote: >My application creates additional process using fork() function. >Created child process listens on a socket and exits when it receives >anything. The main process checks the child PID using kill(pid, 0) >with child PID as a parameter. Even when the child has exited this >function call returns 0. When I have supplied any PID which hasn't >ever existed it's fine and kill(non-existentPID, 0) returns -1. > >Has anyone experienced something like this? This seems like a perfect place for a simple test case. For instance: #include #include #include #include #include int main (int argc, char **argv) { int pid; if (argv[1]) pid = atoi(argv[1]); else if ((pid = fork ()) == 0) { puts ("forking a process and then exiting"); exit (0); } else { int dummy; wait (&dummy); } printf ("%d = kill (%d, 0)\n", kill (pid, 0), pid); exit (0); } I tried the above with no argument and with an argument of a previously forked-and-exited process. Both cases produced the expected result, as did trying this on a running process. I suspect that you are not 'wait()'ing for the process to exit before checking if it exists. kill(pid, 0) will succeed on both linux and cygwin if the process is not reaped by calling wait (or waitpid, etc.) first. 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/