killing processes thru' C programs
Chris Torek
torek at elf.ee.lbl.gov
Mon Apr 29 01:23:12 AEST 1991
In article <1991Apr24.144240.3322 at uoft02.utoledo.edu>
grx0736 at uoft02.utoledo.edu writes:
>does anyone know how to kill processes through C programs if only
>the name of the running process is known, and not its pid.
The `name' of a process *is* its pid. The `command' text ps prints
is purely for your convenience in case you have forgotten what the
process named `12345' might be doing.
>The call to this function could be something like
>
> kill_process("process_name");
>
>I would not like to do this by using ps, or by executing a
>shell script from within the C program.
Consider something like:
$ foo & foo &
7179
7180
$ your_program
One process is named 7179, the other 7180. Both of them were started
with the command `foo'. Which one do you want to kill?
Now, if you start each process yourself, or if you are willing to run
`ps' or something equivalent, you can of course associate your own
arbitrary strings with each PID. Since you control this, you can make
the mapping invertible and do whatever you like.
--
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA Domain: torek at ee.lbl.gov
More information about the Comp.unix.questions
mailing list