godin@ireq.hydro.qc.ca (Andre Godin 8926) (06/12/90)
I have a process (written in C) running under SunOS 4.0.3 that have to find out if a process exist, knowing only his name. Is there a system call (or something else) that can tell me if a certain process is active? Thanks in advance. ----------------------------------------------------------------- Andre GODIN Internet: godin@ireq.hydro.qc.ca HYDRO-QUEBEC MONTREAL, CANADA
gwyn@smoke.BRL.MIL (Doug Gwyn) (06/13/90)
In article <1629@s3.ireq.hydro.qc.ca> godin@ireq.hydro.qc.ca (Andre Godin 8926) writes: > I have a process (written in C) running under SunOS 4.0.3 that >have to find out if a process exist, knowing only his name. Processes don't have names, only numbers (PIDs). The image that was exec()ed came from a file that had a name, but the process could easily alter the only record of the name assigned to its argv[0], which is normally set to the "simple part" of the file name by the shell used to exec() the process. (But that is just a convention, not necessarily followed by all exec()ers.) > Is there a system call (or something else) that can tell me if >a certain process is active? kill(pid,0) will tell you whether or not process #pid is active, assuming you have appropriate permissions.
tif@doorstop.austin.ibm.com (/32767) (06/14/90)
In article <13095@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes: >Processes don't have names, only numbers (PIDs). The image that was >exec()ed came from a file that had a name, but the process could >easily alter the only record of the name assigned to its argv[0], I thought that the "name" was stored in two separate places? argv[0] was just one place. I was led to believe that this is the difference between "ps" and "ps -f". The output of "ps -f" can be tinkered with but the output of "ps" (according to my info) was guaranteed. For instance, when you run nethack (I think it was), it tried to hide itself by changing its name. "ps -f" would give "-" as the name, but just "ps" would give "nethack". (I have come to believe that the latter name is what is used for process accounting as well.) Am I completely off? (Mail may not make it to me...) Paul Chamberlain | I do NOT represent IBM tif@doorstop, sc30661@ausvm6 512/838-7008 | ...!cs.utexas.edu!ibmaus!auschs!doorstop.austin.ibm.com!tif
guy@auspex.auspex.com (Guy Harris) (06/15/90)
>I thought that the "name" was stored in two separate places?
It is, but that's not a "name" in the sense that it uniquely identifies
the process. It's just the first N characters of the last component of
the pathname of the last program "exec"ed within that process.
I.e., there are *lots* of processes "named" "sh" or "csh" on most
machines....
gwyn@smoke.BRL.MIL (Doug Gwyn) (06/15/90)
In article <2546@awdprime.UUCP> tif@doorstop.austin.ibm.com writes: >Am I completely off? Apparently your system keeps the name somewhere in the u-area. Not all UNIX systems do that..
guy@auspex.auspex.com (Guy Harris) (06/16/90)
>Apparently your system keeps the name somewhere in the u-area. Not >all UNIX systems do that.. Most do, though (V7, x.yBSD, S3, S5Rx, and all derivatives of the aforementioned with which I've worked); that's what's written to the kernel process accounting file when a process exits.