4

I have always heard about background (but not desktop background) processes. But I do not understand what they really are. As an example, please look at the answer of this link what is technical difference between daemon, service and process ? I quote here:

Daemons - Daemon ... They are the processes which run in the background and are not interactive. They have no controlling terminal...

What is their usage? Also are there any related commands to show processes running in background?

Mohammad Reza Rezwani
  • 10,286
  • 36
  • 92
  • 128

4 Answers4

9

The simple definition is a process that isn't connected to an active terminal or display... But there are multiple ways of achieving this:

  • Most of what we consider backgrounded processes are system services. These will often be a started by a high-level init daemon (Upstart, Systemd, etc) and usually remain a child of that daemon. It will have its output remanded by the init daemon for logging purposes.

  • A disassociated process is where you change the parent of process to PID=0, /sbin/init. This means that even if you close your terminal or X session, the process will remain (as long as it doesn't depend on other things — like an X session). There are many ways of accomplishing this. Unless otherwise redirected, nothing happens to the output of disassociated processes after their terminal dies.

    It's important to note that disassociated doesn't neccessarily mean background but if the current terminal dies, the process is automatically considered "in the background" because it has no way of managing its IO.

  • Then there are virtual shells that themselves can run in the background and "hold" your active processes open for you. screen is probably the best example of this. It allows you to disconnect and reconnect to various terminal sessions which is handy if you need to preserve a terminal workflow on a server (or run something with output indefinitely, like irssi, an IRC client).

  • Lastly, there is the shell definition. Many shells (command line interfaces like Bash) allow you to background a process. This simply means the IO files STDOUT, STDIN and STDERR are disconnected from the current terminal. The process carries on running in its own thread and you're given another prompt. The process isn't automatically disassociated so if the Bash session closes, so do all its background tasks. Here's a simple example with Bash.

Oli
  • 293,335
7

Background means that a process is running on your system that is not visible on the desktop (ie. it does not have to have an application on the desktop open).

The command to view ALL processes is called 'ps'. Example with ps -ef:

 ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 apr10 ?        00:00:02 /sbin/init
root         2     0  0 apr10 ?        00:00:00 [kthreadd]
root         3     2  0 apr10 ?        00:00:07 [ksoftirqd/0]
root         5     2  0 apr10 ?        00:00:00 [kworker/0:0H]
root         7     2  0 apr10 ?        00:00:33 [rcu_sched]
root         8     2  0 apr10 ?        00:00:00 [rcu_bh]
root         9     2  0 apr10 ?        00:00:01 [migration/0]
root        10     2  0 apr10 ?        00:00:02 [watchdog/0]
root        11     2  0 apr10 ?        00:00:02 [watchdog/1]
root        12     2  0 apr10 ?        00:00:01 [migration/1]
root        13     2  0 apr10 ?        00:00:07 [ksoftirqd/1]
root        15     2  0 apr10 ?        00:00:00 [kworker/1:0H]

It is a lot longer. If you want to find chromium for instance you can do ps -ef | grep chromium like so:

ps -ef |grep chrom
xxxxxx    2874  1207  0 apr10 ?        00:54:28 /usr/lib/chromium-browser/chromium-browser --enable-pinch
xxxxxx    2880  2874  0 apr10 ?        00:00:04 /usr/lib/chromium-browser/chromium-browser --enable-pinch
xxxxxx    2881  2874  0 apr10 ?        00:00:00 /usr/lib/chromium-browser/chrome-sandbox /usr/lib/chromium-browser/chromium-browser --type=zygote
xxxxxx    2882  2881  0 apr10 ?        00:00:00 chromium-browser --type=zygote                          
xxxxxx    2888  2882  0 apr10 ?        00:00:00 chromium-browser --type=zygote                          

Popular programs to view processes are top and htop.

You can use this list to kill a process from command line.

System monitor can be used to view background tasks:

enter image description here

Rinzwind
  • 299,756
  • So it is only about the visibility to the user? Not about process priority? – fikr4n Apr 15 '14 at 10:40
  • @BornToCode No, priority has nothing to do with it. Just the presence or absence of a user interface. – Jos Apr 15 '14 at 11:32
2

A background process is a computer process that runs "behind the scenes" (i.e. in the background) and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification.

From a the command line, a background process can be launched using the & operator. The bg utility can resume a suspended job, running it in the background. Using the fg utility will associate a background process with its parent terminal, bringing it into the foreground. The jobs utility will list all processes associated with the current terminal and can be used to bring background processes into the foreground.

  • Example:

    To send a running process (running in a terminal) to the background, just hit Ctrl+z and call the bg command:

    sylvain@sylvain-ThinkPad-T430s:~$ sleep 50
    ^Z
    [1]+  Stopped                 sleep 50
    sylvain@sylvain-ThinkPad-T430s:~$ bg
    [1]+ sleep 50 &
    

    Now you can type other commands in your terminal while the sleep command is running.

Source

1

Background process is just process that run independently on background and does not affect to the any of the foreground process.

You can refer: http://cs.brown.edu/courses/bridge/1998/res/UnixGuide.html for more details.

Prakash V Holkar
  • 2,561
  • 7
  • 22
  • 29