How do I check if a pid is running?

Noah Spurrier noah at noah.org
Tue May 14 02:54:23 EDT 2002


Yes, indeed, UNIX is a dark and grotty operating system.
It's filled with things like this.

What I find particularly amusing is the fact that while
POSIX.2 defines a standard for a command line
process status (ps), POSIX.1 does not define a standard
for a system call to get process status.
Thus it seems that the only portable way to get a process status
is to do a system call to the 'ps' command line utility.
The fact that nobody really fully complies with POSIX seems 
to make this whole notion of portability a cruel joke anyway.

It looks like we are stuck with this for a long, long time.
I can't imagine anyone coming out with a truly new OS.
It's like the QWERTY keyboard. After a while you are
committed and eventually society becomes stuck on a
standard that was more of a historical accident that
a work planning and engineering.

But this is what makes UNIX more fun than Windows.
I actually get quite a bit of pleasure at figuring this stuff out.

Of course, that whole "kill (pid, 0)" thing turned out 
not to work very well anyway. It's very platform dependent.
It worked on every platform except the one I needed it to work on.

Yours,
Noah

----- Original Message ----- 
From: "Kragen Sitaker" <kragen at pobox.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Monday, May 13, 2002 8:46 PM
Subject: Re: How do I check if a pid is running?


> "Noah" <noah at noah.org> writes:
> > Thanks, this seems to work. In fact the man page for kill
> > says that signal 0 can be used to check the valifity of a pid.
> 
> Of course!  How logical!  Just the other day I was thinking, "How can
> I test whether or not a process exists?"  The very first thing that
> occurred to me was, "I wonder if the man page for kill(2) suggests a
> way to do that?"
> 
> Not.
> 
> 





More information about the Python-list mailing list