8

I have the pid and I just stopped a program using

kill -stop PID

Now I want to continue it by doing

kill -cont PID

But only if it's already stopped. How would I check to see if it's stopped or running?

2
  • you say a program in the title, so you mean the name or you mean the PID like in the example? Commented Nov 6, 2016 at 15:54
  • Do you want to continue it in the foreground (grabbing the terminal) or in the background? Commented Nov 6, 2016 at 15:57

3 Answers 3

8

You can check whether the process is in stopped state, T is ps output.

You can do:

[ "$(ps -o state= -p PID)" = T ] && kill -CONT PID
  • [ "$(ps -o state= -p PID)" = T ] tests whether the output of ps -o state= -p PID is T, if so send SIGCONT to the process. Replace PID with the actual process ID of the process.
5

Another way would be

pid=1
status=`cat /proc/$pid/wchan`
if [ "$status" == "do_signal_stop" ] ; then
  echo "$pid sleeps: $status"
else
  echo "$pid does not sleep: $status"
fi
-4
ps -e | grep | PROGRAM 

or

while true;
do
kill program 
done 
wait 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.