Bash Job Control – How to Stop, Stack, and Use `fg`

bashjob-controljobs

Job control is probably my favorite thing about Linux. I find myself, often, starting a computationally demanding process that basically renders a computer unusable for up to days at a time, and being thankful that there is always CTRL-Z and fg, in case I need to use that particular computer during that particular time period.

Sometimes, however, I want to insert a job onto the job stack. I've never figured out how to do that.

I'm using bash.

It would probably look something like:

$ ./reallybigjob
^Z
[1]+  Stopped                 reallybigjob
$ (stuff I don't know) && ./otherbigjob
$ fg

Best Answer

There is no job stack, each job is handled independently.

You can do fg; otherbigjob. That will put reallybigjob back to the foreground, then when the fg command stops run otherbigjob. This isn't the same thing as queuing otherbigjob for execution after the first job: if you press Ctrl+Z then otherbigjob starts immediately. If you press Ctrl+C then reallybigjob is killed. You can't leave otherbigjob in the background and queue another job after it.

If the jobs are CPU-intensive, then the batch utility can let you schedule the next job when the CPU isn't busy.

Related Question