Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: killing processes thru' C programs Message-ID: <12582@dog.ee.lbl.gov> Date: 28 Apr 91 15:23:12 GMT References: <1991Apr24.144240.3322@uoft02.utoledo.edu> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 33 X-Local-Date: Sun, 28 Apr 91 08:23:12 PDT In article <1991Apr24.144240.3322@uoft02.utoledo.edu> grx0736@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@ee.lbl.gov