2

I often start a long running command that is bound to either CPU, Disk, RAM or Internet connection. While that is running, I find that I want to run a similar command. Let's say downloading something big.

Then I start a shell with wget ...1 and let it run. I could open another shell and run the other wget ...2, but now they would fight for the bandwidth. When I just type the second command into the running shell, it will execute that later on, since wget is not interactive.

Is there a reasonable way to do this with either Bash or Fish Shell?

5

If you have already running wget http://first in foreground you can pause it with CTRL+z and then return it back to work with another command right after it:

fg ; wget http://second

It should work in most cases.

If that way is not acceptable, you should go with lockfile. Or even just to monitor the process via ps (lockfile is better).

  • 1
    Note that bash has a builtin command named wait. You can use it on PIDs or job numbers. To try it out, issue a sleep 15 & and then a wait %1 ; echo hi. As I said you can also specify a PID instead of the %n. – mreithub May 26 '14 at 19:02
  • Lockfiles are a symptom of poor job control. What happens if the first process dies without cleaning up its lockfile? Your first solution looks good, I am not sure whether that scales to multiple tasks in the queue. But what @mreithub said should be able to get it. – Martin Ueding May 27 '14 at 14:21
  • Nope, unfortunately it doesn't scale to multiple tasks. In construction sleep 100 ; echo test echo will be executed immediately after ctrl+z. – rush May 28 '14 at 10:52
0

One can install a full blown job queue management like HTCondor and then queue the jobs there. On Debian it is easy to set it up for a single user on a machine. For most cases, this is probably plain overkill.

0

You may find Task Spooler helpful.

Quoting from the application description,

Task spooler is a Unix batch system where the tasks spooled run one after the other. The amount of jobs to run at once can be set at any time. Each user in each system has his own job queue. The tasks are run in the correct context (that of enqueue) from any shell/process, and its output/results can be easily watched.

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.