Saturday, May 4, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 2944  / 1 Year ago, mon, january 2, 2023, 2:53:51

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?


More From » command-line

 Answers
2

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.



[#26017] Tuesday, January 3, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rmiend

Total Points: 292
Total Questions: 101
Total Answers: 111

Location: Azerbaijan
Member since Tue, Aug 9, 2022
2 Years ago
rmiend questions
Tue, Jan 18, 22, 23:52, 2 Years ago
Sat, Sep 17, 22, 15:44, 2 Years ago
;