Put an executing program into the background
[[email protected] 01]# Ctrl+Z
This causes the program to be moved to the background, but cannot continue output (in paused state)
[[email protected] 01]# ./test1-1 1552227155222715522271552227^Z[1]+ 已停止 ./test1-1[[email protected] 01]# [[email protected] 01]# [[email protected] 01]# jobs[1]+ 已停止 ./test1-1
Let the daemon continue to run in the background
[[email protected] 01]# bg %1[1]+ ./test1-1 &1552227[[email protected] 01]# 155222715522271552227^C
List background Programs
[[email protected] 01]# jobs
Show list of programs that have entered the background
[[email protected] 01]# jobs[1] 已停止 ./test1-1[2]- 已停止 ./test1-1[3]+ 已停止 man jobs
where + is the countdown to the first background process,-is the second-to-last background process, ahead of the background process sequence number
[[email protected] 01]# jobs[1]- 已停止 ./test1-1[2]+ 已停止 ./test1-2
Switch a specific daemon to the foreground
[[email protected] 01]# fg %n
where n is the background process ordinal in the jobs list
[[email protected] 01]# fg %1./test1-115522271552227
View Parent Process identity
[[email protected] 01]# ps f PID TTY STAT TIME COMMAND 49561 pts/1 Ss 0:00 -bash 49959 pts/1 T 0:00 \_ ./test1-1 49960 pts/1 T 0:00 \_ ./test1-2 49962 pts/1 R+ 0:00 \_ ps f 2496 tty1 Ss+ 0:00 -bash
Use PS f to display all processes in a tree to see whether the parent process of test1-1 Test1-2 is-bash
View process identity on new terminal
[[email protected] ~]# ps f PID TTY STAT TIME COMMAND 50060 pts/3 Ss 0:00 -bash 50093 pts/3 R+ 0:00 \_ ps f 50010 pts/2 Ss+ 0:00 -bash 49561 pts/1 Ss+ 0:00 -bash 49959 pts/1 T 0:00 \_ ./test1-1 49960 pts/1 T 0:00 \_ ./test1-2 2496 tty1 Ss+ 0:00 -bash
After the new terminal is opened Test1-1 and Test1-2 's parent process is PTS/1-bash is the old terminal, the-bash of the new terminal is PTS/3, this use of jobs has no test1-1 and test1-2
Log out terminal when pressing CTRL+D
[[email protected] 01]# 登出
Show a stopped task, then use PS-EF to view the list, background tasks still exist
Press once again to Ctrl+d, the terminal has been logged out, switch to another terminal to view
Last login: Sun Oct 15 18:26:48 2017 from 192.168.80.1[[email protected] ~]# ps -ef | grep testroot 49959 1 0 18:27 ? 00:00:00 ./test1-1
The process continues to run after adoption by the INIT process, calling the orphan process to place the program directly in the background execution &
[[email protected] 01]# ./test1-1 &
This enables the program to continue running in the background automatically and output
[[email protected] 01]# ./test1-1 &[1] 49856[[email protected] 01]# 15522271552227
Keep daemon in existence after terminal end
Using daemons to keep a process from terminating as a parent process
daemon(0,0);
The state meaning in Ps-ef
D 不可中断 Uninterruptible sleep (usually IO)R 正在运行,或在队列中的进程S 处于休眠状态T 停止或被追踪Z 僵尸进程W 进入内存交换(从内核2.6开始无效)X 死掉的进程< 高优先级N 低优先级L 有些页被锁进内存s 包含子进程+ 位于后台的进程组;l 多线程,克隆线程 multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
Linux Guard Service-foreground process and background process switch