reiner@jabberwock.shs.ohio-state.edu (Reiner Wilhelms) (08/30/90)
It is rather easy to obtain the process Id of a process via the system
call getpid(), and of the parent process via getppid().
However, how can I obtain the process id of a "stranger": some other
process, running on the same machine, if I just know its name?
Of course, it is possible to call ps, and then search for the name in
its output. I wonder if there is any system call or ugly trick which
does a simpler job, like:
{
int pid,errorcode;
....
errorcode = pid_by_name("Stranger",&pid);
if (errorcode == THERE_IS_NO_ONE_WITH_THAT_NAME)
sprintf(stderr,"Stranger is not running\n");
....
}
Is there something like pid_by_name() in Unix?
Or, to put it different, what does ps do?
Thank you for any hint.
Reiner
gwyn@smoke.BRL.MIL (Doug Gwyn) (08/31/90)
In article <266@jabberwock.shs.ohio-state.edu> reiner@jabberwock.shs.ohio-state.edu (Reiner Wilhelms) writes:
-It is rather easy to obtain the process Id of a process via the system
-call getpid(), and of the parent process via getppid().
-However, how can I obtain the process id of a "stranger": some other
-process, running on the same machine, if I just know its name?
Processes do not HAVE names, just PIDs.
I don't know what problem you're trying to solve, but you're going
about it the wrong way.