lkml.org 
[lkml]   [1996]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Kill system call
Date
From
In message <199603211840.TAA09725@i17linuxb.ists.pwr.wroc.pl>,Marek Michalkiewi
cz writes:
> Nick Randell:
> > I have a process, which forks off a child. The child process has a
> > different EUID to the parent. The child sends the parent a signal to
> > check that it is still alive, but the kill system call returns EPERM
> > whereas on all the other unix systems the software is running on the
> > call returns 0.
> >

Not so.
Sequent Dynix/ptx which is POSIX compliant returns EPERM also.
The POSIX spec clearly states that error checking is performed.
If this were not that case, then in the "normal" situation where parent
and child have the save EUID, you could run into the situation (on a busy
system with a large number of running processes) that
kill(pid, 0);
would return 0 when, in fact, your process had died and a completely
different one to was now running. You wouldn't be able to tell that it wasn't
your process.

I'm curious as to what these other systems are. As I read the spec, they're
non-compliant. It clearly states that normal error checking is performed.

> > I have patched the applications source code to check for EPERM on Linux
> > but the reply I got mentioned that the Linux kernel handling is
> > incorrect.
>

No, the other platforms are wrong (or dubious as best). Linux is doing the
right thing.

> It may be better to check for ESRCH - if you get this error, you know
> this process doesn't exist. This should work everywhere:
>
> if (kill(pid, 0) == -1 && errno == ESRCH) {
> /* process doesn't exist ... */
> } else {
> /* process exists ... */
> }

This would be the correct solution in this case - or simply use waitpid(2)
with the options set to WNOHANG|WNOWAIT to "peek" and see if the process
is still running.

t

--
Tim Wright, Worldwide Technical Services, | Email: timw@sequent.com
Sequent Computer Systems Inc., 15450, |
SW Koll Parkway, Beaverton, Oregon 97006 | Phone: +1-503-578-3822
"Nobody ever said I was charming, they said "Rimmer, you're a git!"" RD VI




\
 
 \ /
  Last update: 2005-03-22 13:36    [W:0.149 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site