Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: how to queue some jobs in the background?

Tags:

linux

queue

Here is the functionality I am looking for (and haven't quite found):

I have x processes that I want to run sequentially. Some of them could be quite time consuming.

I want these processes to run in the background of my shell.

I know about nohup, but it doesn't seem to work perfectly...assuming job1 is a time consuming job, if I ctrl+c out of the blank line that I get after doing nohup job1 && job2 && job3 &, then job2 and job3 won't run, and job1 might or might not run depending on how long I let nohup run.

Is there a way to get the functionality I want? I am ssh'ed into a linux server. For bonus points, I'd love it if the jobs that I queued up would continue running even if I closed my connection.

Thanks for your help.

EDIT: A small addendum to the question: if I have a shell script with three exec statements

exec BIGTHING exec smallthing exec smallthing

will it definitely be sequential? And is there a way to wrap those all into one exec line to get the equivalent functionality?

ie exec BIGTHING & smallthing & smallthing or && or somesuch

like image 207
A Question Asker Avatar asked Jan 04 '11 15:01

A Question Asker


3 Answers

I do agree that screen is very handy tool. There is additional command line tool enqueue - that enables enqueuing of additional jobs as needed i.e. even when you had already started one of the jobs, you can add another one when the first one is already running.

Here's sample from enqueue README:

$ enqueue add mv /disk1/file1 /disk2/file1
$ enqueue add mv /disk1/file2 /disk2/file2
$ enqueue add beep
$ enqueue list
like image 88
myroslav Avatar answered Nov 14 '22 16:11

myroslav


Use screen.

  1. ssh to the server
  2. run screen
  3. launch your programs: job1;job2;job3 - separated with semicolons, they will run sequentially
  4. Detach from the screen: CTRL-A, D
  5. logout from the server

(later)

  1. ssh to the server
  2. run screen -r
  3. and you are in your shell with your job queue running...
like image 35
eumiro Avatar answered Nov 14 '22 16:11

eumiro


Alternatively, if you want a bit more control of your queue, e.g. the ability to list and modify entries, check out Task Spooler. It is available in the Ubuntu 12.10 Universe repositories as the package task-spooler.

like image 32
tachylatus Avatar answered Nov 14 '22 16:11

tachylatus