0

Is there a fork or easy mod of the linux kill command to provide feedback? I'd like to avoid the cycle of:

ps acx | grep rogue_agents
killall rogue_agents # alternately, kill 007
ps acx | grep rogue_agents # did it work?

It would be a nice bonus if it upgraded to kill -9 after some specified period of time.

1
  • 1
    pkill might condense the first two lines into one.
    – Journeyman Geek
    Jan 12, 2014 at 0:06

1 Answer 1

3

You might want to use -w with killall for that:

   -w, --wait
          Wait  for  all  killed  processes to die. killall checks 
          once per second if any of the killed processes still exist
          and only returns if none are left.  Note that killall may
          wait forever if  the  signal  was ignored, had no effect,
          or if the process stays in zombie state.

So killall -w rogue_agents would be enough.


Edit: For the additional bonus question in your edit...
(about upgrading it to a kill -9 after some specified period of time) You could try the following:
(i can't try this myself at the moment because i have no rogue processes :)

timeout 8 killall -w rogue_agents
timeout 8 killall -9 -w rogue_agents

This will do a killall with a wait. The timeout 8 makes it wait only 8 seconds after which you can do the killall -9. I also made that one wait 8 seconds. If the killall -9 isn't done after 8 seconds there is really something wrong and it would need manual investigation.

You could of course build in a test to only execute the second line if there are still rogue_agents present after the initial killall after 8 seconds. And an echo with an error if the process is still active after the second killall -9.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .