1

I executed a command like this: nohup some_command &. Now this command is in the background. I can see it with the command jobs.

Example output:

[1]+  Running                 nohup some_command &

Is it somehow possible to have a live representation of the status that comes from the jobs command, similar to how top works? So that when nohup some_command & completes, it immediately disappears from the list?

  • 1
    Have you tried watch? – Jeff Schaller Jul 26 '15 at 2:41
  • This is kind of overkill, but you could always start a shell (as root) with unshare -fp --mount-proc bash, run a bunch of things in that shell, and then run top. – user3188445 Jul 26 '15 at 6:40
3

If all you want is for job completion notifications to be printed immediately, even if you're at typing a prompt or if some other job is in the foreground, then just run set -o notify.

If you want a foreground command that displays the status of background jobs from the current shell, you can run jobs in a loop. It's easy to do it in full screen:

tput clear
jobs
while sleep 1; do
  tput clear
  jobs
done

If you want to display the list below the prompt without clearing the screen, save the cursor position at the beginning and restore it on each run:

tput sc
jobs
while sleep 1; do
  tput rc
  jobs
done
  • This is great and helps me a lot, but I would actually like something more like the top command, except for registered background jobs. Essentially a list of all active jobs that updates when the status changes. – Automatico Jul 26 '15 at 18:15
  • @Cort3z Do you mean something you'd launch in the same terminal window? Or in another terminal window? I don't understand how you want the list to be displayed and how you'd interact with it. – Gilles Jul 26 '15 at 20:16
  • Try to write top in terminal. I want the exact same thing, only it displays job status, not process status. A foreground program which has a live update of all the background jobs. – Automatico Jul 27 '15 at 2:19
  • @Cort3z Ok. I've updated my answer, I think this is what you're looking for. – Gilles Aug 3 '15 at 1:15
0

You can create a shell function :

myjobwatch() { while true; do jobs; sleep 2; clear; done; }

Then just execute myjobwatch

  • Wouldn't this clear the entire console? – Automatico Jul 26 '15 at 18:12

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.