Search code examples
bashshbackground-processjobs

Creating suspended background jobs


Using Bash, how can I launch background jobs in the suspended/stopped state?

I have to execute a hundred or so memory-intensive, time-consuming processes. Running them sequentially would take a long time:

for i in inputs-list; do
  memory-hog $i
done

Whereas running them all concurrently would kill my machine:

for i in inputs-list; do
  memory-hog $i &
done

I would like my processes to start as background, suspended jobs; then I would use bg to resume some of them, while monitoring the memory consumption.


Solution

  • Start each process in the background then send SIGSTOP:

    for i in inputs-list; do
      memory-hog $i &
      kill -SIGSTOP $!
    done