Danilo Piazzalunga
Danilo Piazzalunga

Reputation: 7802

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.

Upvotes: 0

Views: 136

Answers (1)

Tim
Tim

Reputation: 4948

Start each process in the background then send SIGSTOP:

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

Upvotes: 3

Related Questions