Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!bria!mike From: mike@bria.UUCP (Michael Stefanik) Newsgroups: comp.unix.questions Subject: Re: killing processes thru' C programs Message-ID: <231@bria.UUCP> Date: 28 Apr 91 09:31:41 GMT References: <1991Apr24.144240.3322@uoft02.utoledo.edu> Reply-To: uunet!bria!mike Organization: MGI Group International, Los Angeles, CA Lines: 32 Is there an entry in the FAQ for this yet? In an article, 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 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?