Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know that you can use this to start a process in the background, without getting the notification when the process is put in the background and when it is done like so:

(command &) &> /dev/null

However this removes the option to trap when the process finishes (trap child_done CHLD).

How can I have both?

share|improve this question
add comment

3 Answers

task-spooler might help you.

As in freshmeat.net:

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. It is very useful when you know that your commands depend on a lot of RAM, a lot of disk use, give a lot of output, or for whatever reason it's better not to run them all at the same time, while you want to keep your resources busy for maximum benfit. Its interface allows using it easily in scripts.

Task-spooler is available in Debian, Ubuntu and other distros.

It lets you have a queue of tasks to run, and access their outputs just at wish.

For example:

$ tsp sleep 5
0 
$ tsp sleep 5 
1
$ tsp
ID   State      Output               E-Level  Times(r/u/s)   Command [run=1/1]
2    running    /tmp/ts-out.ZWn6Le                           sleep 5
1    finished   /tmp/ts-out.Fhlcle   0        5.00/0.00/0.01 sleep 5

If you run a lot of jobs in background, it will definitely help you.

You can either run them sequentially or in a preset amount of slots. You can also establish dependencies among the tasks (run task1 only if task0 completed successfully).

share|improve this answer
add comment

You may invoke zsh as a non-interactive shell to disable job notifications.

zsh -c '
   trap "echo trapped child_done" CHLD
   sleep 5 &
   #wait
   sleep 10 # simulate other running cmds
   echo script done
'
share|improve this answer
add comment

See the following example :

trap 'echo "DONE"' 0
{ find /usr & } &> /dev/null
wait

That works well. No need ( ) : that makes a not needed subshell. { } are just grouping commands.

share|improve this answer
    
That prints [2] 49591 and [2] + 49591 exit 1 find /usr, when it should print neither of these! –  Tyilo Oct 7 '12 at 0:28
    
Sorry, misunderstood your question so. –  sputnick Oct 7 '12 at 0:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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