1

I have 2 questions about starting the processes in the background:

  1. Why does starting a process in the background like so:

    ./my_program &

    (my_program have exe permission set of course) doesn't make the bash to print the command prompt like any other commands? It just left a empty new line with blinking cursor.

  2. When i run a next new processes in the background bash displays sth. like that:

    ./my_program & [30] 1439 [27] Done ./my_program [28] Done ./my_program [29] Done ./my_program

    does this mean that starting another extra processes in the background makes the system to display an info about the previews processes ([27], [28], [29] lines) as long as the currently started) ([30] line)?

1
  • What happens if you just press <return> again? do you get a prompt?
    – Attie
    Dec 10, 2018 at 16:22

1 Answer 1

0
  1. This shouldn't happen. When you run a command in the background bash usually just prints the job number and pid (see below) and then drops back to a command prompt.

    The only reason I know of that leads bash to leave you with a new line in this situation is if your command doesn't actually exist, as it will somehow give the error message for that after printing PS1:

    $ nonexistant_command &
    [1] 13856
    $
    nonexistant_command: command not found
    <empty line with blinking cursor here>
    

    Whatever the cause may be, pressing enter while on this empty line should print a new line with your usual prompt (and, possibly, the message that the job you just spawned finished; see below).

  2. The additional output you see is bash telling you about current background jobs:

    First, it tells you the current job number of any newly created background process together with its pid, like so:

    $ some_command &
    [1] 1234
    

    This means that the command some_command is now being run with the pid 1234 as job 1.

    Once a background job finishes, bash will notify you of this the next time it prints a command prompt (whether it be because you spawned another background process, ran a command in the foreground or simply pressed enter with an empty command line) by printing a message like this:

    [1]  Done                    some_command
    

    This means that the job with the number 1 which ran some_command has now finished.

    To find out what background jobs bash is currently tracking, you can use the jobs builtin like so:

    $ jobs
    [1]  Running                 some_command &
    [2]  Running                 some_other_command &
    

    To bring a job to the foreground, you can use fg:

    $ fg 2
    some_other_command
    

    For more info on this, try help jobs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .