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
[1]+  Stopped                 reallybigjob
$ (stuff I don't know) && ./otherbigjob
$ fg
  • There is no "stack". Are you trying to "pause" reallybigjob, start otherbigjob, and have reallybigjob automatically "resume" when otherbigjob is done? – Mat Jan 28 '12 at 14:12
  • at (and atq) could be handy here, but I'm not entirely sure if two commands run at now run after each other... (some examples) – sr_ Jan 28 '12 at 14:14
  • I want to resume reallybigjob and enter otherbigjob immediately following the termination of reallybigjob. the same command would also allow me to add 100 jobs in a predetermined sequence, resume reallybigjob, then enter otherbigjob001, otherbigjob002, etc.. – ixtmixilix Jan 28 '12 at 15:33
  • 1
    Related: How can I queue processes? – Gilles 'SO- stop being evil' Jan 28 '12 at 22:04

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.

  • 1
    a semicolon. how simple. i knew there would be a way to do the thing i needed to do. thank you. i will definitely also use batch at some point. – ixtmixilix Feb 2 '12 at 0:28

You can have more than one job running or paused in the background:

$ ./reallybigjob &
[1] 873
$ ./otherbigjob &
[2] 875
$ jobs
[1]-  Running                 ./reallybigjob &
[2]+  Running                 ./otherbigjob &
$ fg 1
[1]+  Stopped                 ./reallybigjob
$ fg 2
[2]+  Stopped                 ./otherbigjob
$ jobs
[1]-  Stopped                 ./reallybigjob
[2]+  Stopped                 ./otherbigjob
$bg 1
[1]- ./reallybigjob &
$ jobs
[1]-  Running                 ./reallybigjob &
[2]+  Stopped                 ./otherbigjob

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.