On Wed, 2003-10-29 at 23:03, Daniel Fone wrote: > The tricky part is that I need to store the PID of the command so I can kill > it later. The $! variable is great but it only contains the pid of the perl > script (eg 3273) which, when killed, leaves the tail alive! Is there anyway I > can get the pid of the tail? > > I thought an alternative would be to run "sh -c $CMD &" which also works and > gives us: > 3648 pts/0 S 0:00 sh -c [...] | /usr/bin/perl -n /tmp/sentry_1.pl > 3651 pts/0 S 0:00 \_ tail -f /var/log/messages.2 > 3652 pts/0 S 0:00 \_ /usr/bin/perl -n /tmp/sentry_1.pl > However, when I kill the sh process, both the tail and the perl remain > running.
Using | is a shortcut, and not the only way to use pipes. If you want finer control over your processes use a named pipe. mknod /tmp/td p tail +0f /var/log/messages.2 > /tmp/td 2>&1 & tpid=$! I'm sure you can figure out the rest. Cheers, Rex
