Linux Work Management Methods

put a process in the background
1. The first method
tar -zcf etc.tar.gz /etc &
top &
Put the command in the background and execute it in the background
2. The second method
top
Press ctrl+z shortcut key, put it in the background to pause
 
2. Check the background work
jobs [-l]
Options:
-l: show the PID of the job
Note:
The "+" sign represents the most recent work put into the background, that is, the work that is restored by default when the work is resumed.
The "-" sign represents the second-to-last job put in the background.
 
Three actual combat
1. The command that interacts with the user is placed in the background and it will become stop
[root@localhost ~]# top
top - 13:56:05 up 4:54, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 152 total, 2 running, 150 sleeping, 0 stopped, 0 zombie
%Cpu (s): 0.3 us, 0.7 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016860 total, 342592 free, 317664 used, 356604 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 515716 avail Mem
 
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8955 root 20 0 146128 2012 1420 R 0.7 0.2 0:00.39 top
10 root 20 0 0 0 0 S 0.3 0.0 0:03.12 rcu_sched
11 root 20 0 0 0 0 R 0.3 0.0 0:03.17 rcuos/0
1 root 20 0 126580 7372 2620 S 0.0 0.7 0:08.53 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.04 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.62 ksoftirqd/0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
[1]+ Stopped top
[root@localhost ~]# top &
[2] 8965
[root@localhost ~]# jobs -l
[1]- 8955 Stopped (signal) top
[2]+ 8965 Stopped (signal) top
[root@localhost ~]# vi abc &
[3] 9121
[root@localhost ~]# jobs
[1] Stopped top
[2]- Stopped top
[3]+ Stopped vim abc
 
2. View the processes running in the background
[root@localhost ~]# find / -name abc &
[4] 9150
[root@localhost ~]# jobs
[1] Stopped top
[2]- Stopped top
[3]+ Stopped vim abc
[4] Running find / -name abc &
 
Fourth, resume the work suspended in the background to the foreground for execution
fg % job number
parameter:
% job number: % can be omitted, but pay attention to the difference between job number and PID
 
5. Resume the work suspended in the background to the background execution
bg % job number
Note: The command to resume execution in the background cannot interact with the foreground, otherwise it cannot be resumed to execute in the background.
 
Six actual combat
[root@localhost ~]# jobs -l
[1] 8955 Stopped (signal) top
[2]- 8965 Stopped (signal) top
[3]+ 9121 Stopped (tty output) vim abc
[root@localhost ~]# bg 1
[1] top &
localhost ~]#
 
 
[1]+ Stopped top
[root@localhost ~]# jobs
[1]+ Stopped top
top - 14:18:12 up 5:16, 2 users, load average: 0.00, 0.04, 0.06
Tasks: 154 total, 2 running, 150 sleeping, 2 stopped, 0 zombie
%Cpu (s): 0.3 us, 0.7 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1016860 total, 103060 free, 343720 used, 570080 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 430616 avail Mem
 
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8955 root 20 0 146128 2012 1420 R 1.0 0.2 0:00.55 top
11 root 20 0 0 0 0 R 0.3 0.0 0:03.45 rcuos/0
1 root 20 0 126580 7372 2620 S 0.0 0.7 0:09.12 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.04 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.63 ksoftirqd/0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0
[root@localhost ~]# jobs
[2]- Stopped top
[3]+ Stopped vim abc
[root@localhost ~]# fg
vim abc
[root@localhost ~]# jobs
[2]+ Stopped top
[root@localhost ~]# fg
top
 
top: failed tty set: Interrupted system call.
[root@localhost ~]# jobs

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326143257&siteId=291194637