Linux – How to start a process in suspended state under Linux

background-processlinuxprocess

Practically, I need a process which behaves, as if I had pressed Ctrl+Z just after it started.

Hopefully, it is possible to do such thing using a shell script.

(Also, knowing the resulting PID would be great, so I could continue the process afterwards.)

Best Answer

After starting a process, you can send it SIGSTOP to suspend it. To resume it, send SIGCONT. I think that this little script may help you

#!/bin/bash
$@ &
PID=$!
kill -STOP $PID
echo $PID
wait $PID

It runs process (command send as parameter), suspends it, prints process id and wait until it ends.