Start a Process in Suspended State
20 Aug 2018 Linux tipsUnder some circumstances, I would like to launch the process, then let other programs attach to it. No matter how fast can I type, it is impossible for me to bind the processes from the very beginning. The solution is let the script to launch the process but suspend it immediately.
#!/bin/bash
$@ &
PID=$!
kill -STOP $PID
echo $PID
wait $PID
The script earns enough time for you to do your operations in another terminal, then to resume the process:
kill -CONT $PID
Note: need to replace $PID
with the number printed in the first terminal.
Credits
- How do I start a process in suspended state under Linux? - Thank radious and sciurus for your answer.