The role of the character "&" after running commands in the Linux shell

Source: Internet
Author: User
Tags session id switches

& 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.