Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!hsdndev!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: killing processes thru' C programs Message-ID: <16011@smoke.brl.mil> Date: 30 Apr 91 16:22:06 GMT Article-I.D.: smoke.16011 References: <1991Apr24.144240.3322@uoft02.utoledo.edu> <12582@dog.ee.lbl.gov> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 49 In article <12582@dog.ee.lbl.gov> torek@elf.ee.lbl.gov (Chris Torek) writes: >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. While I was tempted to respond in much the same way, actually it is possible to interpret the original request in a way that might make enough sense to have an adequate solution. #!/bin/sh # zap -- kill all processes matching pattern # adapted from Kernighan & Pike HEAD=head # see below PICK=pick # see below IFS=' ' sig= case $1 in "") echo 'Usage: zap [-2] pattern' 1>&2; exit 1;; -*) sig=$1; shift;; esac # BSD flavor of "ps" assumed: ps -ag | $HEAD 1 exec kill $sig `$PICK \`ps -ag | egrep "$*" | egrep -v 'zap|egrep'\` | awk '{print $1}'` #!/bin/sh # head -- print first few lines of file if [ $# -eq 0 ] then n=10 else case $1 in [0-9]*) n=$1; shift;; *) n=10;; esac fi exec sed -e ${n}q $* #!/bin/sh # pick -- select arguments # adapted from Kernighan & Pike for i do echo -n "$i? " > /dev/tty # BSD or Research UNIX "echo" assumed read response case $response in [yY]*) echo $i;; [qQ]*) break;; esac done < /dev/tty Brought to you by Super Global Mega Corp .com