Way I can queue long running tasks

commandcommand-line-interfaceprocessqueueunix

Is there a way I can do the following in a unix terminal:

  1. Start a long running process
  2. Add another long running process to start when the previous is done
  3. Repeat step 2 until I have queued the processes I need to have run

Reason I ask is that I have some long running stuff I need to do. I could put all the commands in a simple bash script and just execute that, but the problem is that I am not always sure exactly what I need to run. So if I start the script and then remember another one I should run, I need to hit ^C a bunch of times until all the processes are killed, edit the script and add my new process and then start the whole thing again.

What I specifically am doing right now is to copy a lot of large files on to various external hard drives, and since I don't know exactly which ones I need to copy and to where right now I'd like to start the ones I do know I need to copy, and then add to the queue as I figure out the rest.

Hope that made sense… Is anything like this possible?

Best Answer

The shell is perfect for that.

  1. Start the first program.
  2. Press Ctrl-z to suspend the program.
  3. Start the next program.
  4. Repeat steps 2 and 3 to add more programs to the queue. All the programs will be in Suspended mode.
  5. Now run the queue like this:

    while fg; do :; done
    

    You may not suspend this while loop or exit bash until the queue is done.

If you will need to log out (e.g. the programs will run for many days) then consider running the above steps in screen.