& placed after the startup parameter to set this process as a background process
By default, the process is the foreground process, then the shell is occupied, we can not do other operations, for those who do not interact with the process, many times, we want to start in the background, you can start the parameters with a ' & ' to achieve this purpose.
Such as:
Tianfang > Run &
[1] 11319
Tianfang >/GAME.E 1 &
When the process switches to the background, we call it job. Switching to the background will output the relevant job information, with the previous output as [1] 11319 cases: [1] indicates that the job ID is 1,11319 indicates that the process ID is 11319. A process that switches to the background can still be viewed with the PS command.
Switching between front and rear tables
The BG (background) and FG (foreground) commands allow them to switch between the pre-background state.
Daemon process
If a process is always started in the background and cannot be exited by a shell exit, it is a legitimate practice to create it as a daemon. The daemon refers to the long-running background process of the system, similar to Windows services. Daemon information through Ps–a can not see, need to use the –x parameter, when using this command, often also attach-j parameters to view job control information, where Tpgid column is 1 is the daemon process.
Tianfang > PS XJ
PPID PID pgid SID TTY tpgid STAT UID time COMMAND
953 1190 1190 1190? -1 Ss-0:00/bin/sh/usr/bin/startkde
1 1490 1482 1482? -1 Sl 0:00/usr/bin/vboxclient–seamless
1 1491 1477 1477? -1 Sl 0:00/usr/bin/vboxclient–display
The most critical step in creating a daemon is to call the SETSID function to create a new session and become the session Leader. The result of a successful call to this function is:
- Create a new session, the current process becomes session Leader, the ID of the current process is the session ID
- Create a new process group, the current process becomes the leader of the process group, and the ID of the current process is the ID of the process group
- If the current process originally had a control terminal, it would lose the control terminal and become a process without the control terminal.
The role of the character "&" after running commands in the Linux shell