I do a sleep 3 & and the "done" message is displayed as part of the ps command, not right on the console. It doesn't have to be ps. Any command after the sleep is done will have an extra line at the end with the "done" message. Why is that?

OS is centos-7.0, downloaded with vagrant.

[vagrant@localhost ~]$ sleep 3 &
[1] 2838
[vagrant@localhost ~]$ ps
  PID TTY          TIME CMD
 1871 pts/0    00:00:00 bash
 2838 pts/0    00:00:00 sleep
 2840 pts/0    00:00:00 ps
[vagrant@localhost ~]$ ps
  PID TTY          TIME CMD
 1871 pts/0    00:00:00 bash
 2841 pts/0    00:00:00 ps
[1]+  Done                    sleep 3
[vagrant@localhost ~]$

If I do ls > ls.txt the "done" message doesn't go to the file. It is displayed on the console. If I click enter after 3 secs, the message is displayed. Is it in some kind of cache? What happens?


The "Done" message is not managed by the process you executed, but by bash itself to notify you about the end of a background job. That is why it provides the message when there is some console activity.

In bash, you can use :

  • set +m (monitor) to remove this kind of messages if you do not want to see them.
  • set -b (notify) to display the messages without any delay.
| improve this answer | |

man bash says:

   The  shell  learns immediately whenever a job changes state.  Normally,
   bash waits until it is about to print a prompt before reporting changes
   in  a  job's status so as to not interrupt any other output.  If the -b
   option to the set builtin command is enabled, bash reports such changes
   immediately.   Any  trap  on  SIGCHLD  is  executed for each child that
| improve this answer | |

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.