2

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
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
ixtmixilix
  • 13,040
  • 27
  • 82
  • 118
  • 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](http://www.linux-support.com/cms/en/component/content/article/127-delayed-job-execution-on-linux)) – 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?](http://unix.stackexchange.com/q/20952) – Gilles 'SO- stop being evil' Jan 28 '12 at 22:04

2 Answers2

3

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
./reallybigjob
^Z
[1]+  Stopped                 ./reallybigjob
$ fg 2
./otherbigjob
^Z
[2]+  Stopped                 ./otherbigjob
$ jobs
[1]-  Stopped                 ./reallybigjob
[2]+  Stopped                 ./otherbigjob
$bg 1
[1]- ./reallybigjob &
$ jobs
[1]-  Running                 ./reallybigjob &
[2]+  Stopped                 ./otherbigjob
$
Kevin
  • 40,087
  • 16
  • 88
  • 112
3

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 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 02 '12 at 00:28