Sometimes when I wanted to do something like:
long_running_command; second_command
I forget the ; second_command
part. If I don't want to interrupt and restart the long_running_command
(sometimes it's not possible, other times it has run for a significant time before I discover my mistake and that work would be wasted), I typically do something like
ps aux | grep long_running_command
while (kill -0 <pid found above>); do sleep 1; done; second_command
(in another terminal)
and while it works, it results in the following error:
kill: kill <pid> failed: no such process
Is there a way to avoid that error, or a better way to schedule second_command
shortly after long_running_command
finishes.
(I use zsh
on Debian Jessie).
kill
's standard error to the bit bucket:while kill -0 $pid 2>/dev/null; do sleep 1; done; other_command
. – DopeGhoti Aug 07 '17 at 18:28