Summary of commands for controlling the process in Linux
- 2020-05-30 21:44:08
- OfStack
What are the commands that control the process in Linux? Let's take a look
Operating system: Debian 8.5
Note: n below represents the serial number in jobs
1. Check what commands are running in the background in Linux:
jobs
root@wing-01:~ # jobs
[1]+ Stopped python backup_mysql.py wing 1.2.3.4 8888 wing
[2]- Running python backup_mysql.py wing 1.2.3.5 8888 wing &
root@wing-01:~ #
2. Make the process run in the background:
cmd &
root@wing-01:~ # python backup_mysql.py wing 1.2.3.5 8888 wing &
[2] 27716
root@wing-01:~ #
3. Make the background process n run to the foreground:
fg %n
root@wing-01:~ # jobs
[1]+ Stopped python backup_mysql.py wing 1.2.3.4 8888 wing
[2]- Running python backup_mysql.py wing 1.2.3.5 8888 wing &
root@wing-01:~ # fg %2
python backup_mysql.py wing 1.2.3.5 8888 wing
4. Let the foreground n run in the background:
bg %n
# This command applies to passing ctrl-z Suspended process
# Such as the following job In the job1 Is through the ctrl-z Suspended, the program will no longer be occupied CPU , suspend the execution, can be passed top Look at its occupancy CPU At a rate of 0% At this point not only can it be passed fg %n Let its foreground continue to run, also can pass bg %n Let it run in the background
root@wing-01:~ # jobs
[1]+ Stopped python backup_mysql.py wing 1.2.3.4 8888 wing
[2]- Running python backup_mysql.py wing 1.2.3.5 8888 wing &
root@wing-01:~ # bg %1
[1]+ python backup_mysql.py wing 1.2.3.4 8888 wing &
root@wing-01:~ #
# And at that point you go through top, It's starting to take over CPU,CPU The utilization rate is not 0 , indicating that it is already running in the background.
5. Suspend the current program:
ctrl-z
At this point, the program is in a state where CPU does not apply to perform any tasks, that is, the program is in a state of suspension, waiting for it to be awakened with other commands.
root@wing-01:~ # python backup_mysql.py yumin 172.16.33.227 3333 yumin platform test
^Z
[1]+ Stopped python backup_mysql.py yumin 172.16.33.227 3333 yumin platform test
root@wing-01:~ #
6. Suspend the program through PID:
kill -STOP pid
root@wing-01:~ # kill -STOP 28021
[1]+ Stopped python backup_mysql.py yumin 172.16.33.227 3333 yumin
root@wing-01:~ #
# Now you can go through top Look at its occupancy CPU At a rate of 0% , the process has stopped.
7. Restore the program to the background operation through PID:
kill -CONT pid
root@wing-01:~ # kill -CONT 28021
root@wing-01:~ #
# And at that point you go through top, It's starting to take over CPU,CPU The utilization rate is not 0 , indicating that it is already running in the background.
conclusion