Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!aplcen!haven!adm!news From: marwood@ncs.dnd.ca (Gordon Marwood) Newsgroups: comp.unix.questions Subject: Killing the correct process Message-ID: <22332@adm.BRL.MIL> Date: 3 Feb 90 13:53:04 GMT Sender: news@adm.BRL.MIL Lines: 33 The following is a code fragment from get21.sh, which is part of the autoftp software available from simtel20: # Create two sub-shell processes, one for FTP, one for time-out. # Each sub shell has two parts. If the first part is succeeded, a KILL # action will be taken to abort either the TIME-OUT or the FTP process. { ftp "$RemoteHost" tmp0$$; grep sleep tmp0$$ > tmp$$; pd=`$_pid < tmp$$`; kill -9 $pd ; } } & { sleep $ALARM && { ps -x > tmp0$$; grep ftp tmp0$$ > tmp$$; pd=`$_pid < tmp$$`; kill -9 $pd ; } } The problem with this is that "grep sleep" does not necessarily select the "sleep" which belongs to the autoftp process, if there are other "sleep"s running at the same time (from some other unrelated process). Similarly, "grep ftp" is ambiguous if other "ftp"s are running concurrently. At the moment I have put in a workaround which looks for the "sleep" with the correct delay time, and an ftp using the numeric address rather than the hostname. However, this is not a very elegant way of doing things and not 100% foolproof. I would appreciate any assistance that anyone can offer to do these "kill"s more specifically. Gordon Marwood marwood@ncs.dnd.ca