Process Management for Linux operating systems

Source: Internet
Author: User

Tutorial: Linux Process Management is much more powerful than Windows, and all processes are mapped to the/proc directory, we can view the memory data of these processes as we operate on common files.

~ $ Ls-l/proc

Dr-xr-x 7 root 0 1
......
-R -- 1 root 0 version
-R -- 1 root 0 version_signature
-R -------- 1 root 0 vmallocinfo
-R -- 1 root 0 vmstat
-R -- 1 root 0 zoneinfo

~ $ Cat/proc/version
Linux version 2.6.28-11-generic (buildd @ palmer) (gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) # 42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009

1. Job Management

Use "&" to place commands in "background" for execution

~ $ Nano a.txt & # Run the nano editor in the background

[1] 12988

[1] + Stopped nano a.txt

~ $ Jobs # view all currently executed jobs

[1] + Stopped nano a.txt

~ $ Fg 1 # transfer 1 job to the foreground for execution

Press Ctrl + Z to save the program being executed to the background. For background programs in the "Stopped" status, we can use "bg" to make them "Running" in the background ".

~ $ Sleep 1 m # sleep for 1 minute, and press Ctrl + Z to run it in the background.

^ Z
[1] + Stopped sleep 1 m

~ $ Jobs

[1] + Stopped sleep 1 m # The sleep command is "suspended ".

~ $ Bg 1 # Use fg to run sleep in the background.

[1] + sleep 1 m &

~ $ Jobs

[1] + Running sleep 1 m &

We can use the "kill" command to terminate the job.

~ $ Jobs

[1] + Stopped sleep 1 m

~ $ Kill-9% 1

[1] + Stopped sleep 1 m

~ $ Jobs

[1] + Killed sleep 1 m

Kill has several main parameters:-1 reload;-2 Ctrl + C;-9 Force Delete;-15 exit in normal mode.

2. Process Management

"Ps" is used to view the currently running process. There are many parameters, but "aux" is commonly used ".

~ $ Ps aux | more

User pid % CPU % MEM VSZ RSS TTY STAT START TIME COMMAND
Root 1 0.0 0.3 3084 1884? Ss/sbin/init
Root 2 0.0 0.0 0 0? S <[kthreadd]
Root 3 0.0 0.0 0 0? S <08:00 0: 00 [migration/0]
Root 4 0.0 0.0 0 0? S <08:00 [ksoftirqd/0]
Root 5 0.0 0.0 0 0? S <08:00 [watchdog/0]
Root 6 0.0 0.0 0 0? S <08:00 0: 00 [events/0]
Root 7 0.0 0.0 0 0? S <[khelper]
Root 8 0.0 0.0 0 0? S <08:00 0: 00 [kstop/0]
Root 9 0.0 0.0 0 0? S <08:00 0: 00 [kintegrityd/0]
Root 10 0.0 0.0 0 0? S <[kblockd/0]
Root 11 0.0 0.0 0 0? S <[kacpid]
Root 12 0.0 0.0 0 0? S <08:00 [kacpi_notify]
...

Display result column:
USER: USER Account
PID: process ID
% CPU: CPU usage percentage
% MEM: memory usage percentage
VSZ: virtual memory usage
RSS: Fixed memory usage
TTY: Terminal
STAT: running status (R: running; S: sleep; T: terminated; Z: botnets for some reason)
START: START Time
TIME: CPU running TIME
COMMAND: COMMAND Line
We can also directly view a single process.

~ $ Ps 34

PID TTY STAT TIME COMMAND
34? S <0: 00 [kmpath_handlerd]

~ $ Ps-C ksnapd

PID TTY TIME CMD
35? 00:00:00 ksnapd

Unlike static ps output, "top" can dynamically refresh process information (the default interval is 5 seconds ).

~ $ Top

Top-12:02:29 up, 2 users, load average: 0.04, 0.04, 0.01
Task: 113 total, 1 running, 111 sleeping, 0 stopped, 1 zombie
Cpu (s): 0.2% us, 1.3% sy, 0.2% ni, 97.6% id, 0.6% wa, 0.0% hi, 0.0% si, 0.0% st
Mem: 509504 k total, 436672 k used, 72832 k free, 79376 k buffers
Swap: 409616 k total, 0 k used, 409616 k free, 212208 k cached

Pid user pr ni virt res shr s % CPU % mem time + COMMAND
14 root 15-5 0 0 S 1.9 0.0. 08 ata/0
1 root 20 0 3084 1884 S 564 0.0. 43 init
2 root 15-5 0 0 S 0.0 0.0. 00 kthreadd
3 root RT-5 0 0 S 0.0 0.0. 00 migration/0
4 root 15-5 0 0 S 0.0 0.0. 33 ksoftirqd/0
5 root RT-5 0 0 S 0.0 0.0. 00 watchdog/0

Line 1: system startup time; number of online users; system load for 1, 5, and 10 minutes (generally no more than 1. Check if the duration is greater than 5 ).
Row 2: Process statistics. Zombie indicates the number of zombie processes.
Row 3: CPU load statistics.
Row 4: memory usage statistics.
Row 5: virtual memory usage statistics.

Process column information:
PID: process ID
USER: USER Account
PR: Priority (Execution earlier and earlier)
NI: Nice
% CPU: CPU usage percentage
% MEM: memory usage percentage
TIME +: CPU running TIME
COMMAND: COMMAND Line
We can use the "-d" parameter to specify the refresh frequency (in seconds)

~ $ Top-d 1

The "-p" parameter is used to specify a specific process number.

~ $ Top-d 1-p 13952

During running, you can press "h" to enter the Help menu and view shortcut keys such as display and sorting.

3. Process Priority

Each process has a "Priority" attribute, and the system arranges the execution order by Priority (ascending.

PRI (new) = PRI (old) + Nice

Since PRI is determined by the system "dynamic", we need to adjust the priority through Nice.

~ $ Nano &

[1] 15174

[1] + Stopped nano

~ $ Ps-l

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 R 1000 15086 15082 0 80 0-1447-pts/0 00:00:00 bash
0 T 1000 15174 15086 0 80 0-929 signal pts/0 00:00:00 nano
0 R 1000 15177 15086 0 80 0-635-pts/0 00:00:00 ps

~ $ Sudo renice-5 15174 # adjust priority

15174: old priority 0, new priority-5

~ $ Ps-l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 R 1000 15086 15082 0 80 0-1447-pts/0 00:00:00 bash
0 T 1000 15174 15086 0 75-5-929 signal pts/0 00:00:00 nano
0 R 1000 15182 15086 0 80 0-635-pts/0 00:00:00 ps

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.