Killing the correct process
Gordon Marwood
marwood at ncs.dnd.ca
Sun Feb 4 00:53:04 AEST 1990
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" <ftp.get.$$ &&
{ ps -x > 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 at ncs.dnd.ca
More information about the Comp.unix.questions
mailing list