killing processes thru' C programs

Michael Stefanik mike at bria.UUCP
Sun Apr 28 19:31:41 AEST 1991


Is there an entry in the FAQ for this yet?

In an article, 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 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. 

The politically correct answer in this case is "no".  In reality, of
course, there are ways to get process information, but it is implementation
dependant, and highly unportable.

Sepaking in the broadest of terms:

	1. read the kernel's namelist, searching for _proc
	2. seek to the offset in /dev/kmem, and read in the proc table entry
	3. determine if the process is in core or swapped
	4. if in core, read the u area from /dev/mem
	   if swapped, read the u area from the swap device

You may or may not have functions that will provided a nicer way to glean
this information (rather than rummaging around with nlist() and lseek())

-- 
Michael Stefanik, MGI Inc, Los Angeles | Opinions stated are never realistic
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
If MS-DOS didn't exist, who would UNIX programmers have to make fun of?



More information about the Comp.unix.questions mailing list