In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how linux views a process and kills process ps grep kill". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Use top or ps to view processes in linux. Use kill to kill processes.
1. Use top to view the process:
$top
Execute the above command to view the top! But the difficulty is how to sort by the cpu usage of the process.
Perform the following operations in the order of cpu usage:
Press capital O, then press k and then hit enter, and then use R to view the cpu usage! Top's skill commands are posted below:
"change the display
The f key allows you to select what is displayed. Press the f key to display the list of columns, press amurz to show or hide the corresponding columns, and finally press enter to determine.
Press o to change the order in which the columns are displayed. Press lowercase Amurz to move the corresponding column to the right, and uppercase Amurz to move the corresponding column to the left. Finally, press the enter key to confirm.
Press the uppercase F or O key, and then press amurz to sort the processes by the corresponding columns. The uppercase R key reverses the current sort. "
Then there is the meaning of the top parameter:
"150 total total processes
2 the number of processes that running is running
148The number of sleeping sleep processes
Number of processes stopped by 0 stopped
0 zombie number of zombie processes
Cpu0: 67.4% us user space occupies CPU percentage
2.0% sy kernel space occupies CPU percentage
Percentage of CPU occupied by processes that have changed priorities in the process space of 0.0% ni users
30.2% id idle CPU
Percentage of CPU time that 0.0% wa waits for input and output
0.0% hi
0.0% si
0.0% st
Process information area
The details of each process are displayed at the bottom of the statistics area. First of all, let's understand the meaning of each column.
Serial number column name meaning
A PID process id
B PPID parent process id
C RUSER Real user name
D user id of the UID process owner
E user name of the owner of the USER process
F Group name of the owner of the GROUP process
G TTY the terminal name of the startup process. Processes that are not started from the terminal are displayed as?
H PR priority
I NI nice value. Negative values indicate high priority, while positive values indicate low priority.
The last CPU used by j P makes sense only in a multi-CPU environment
K% percentage of CPU time occupied from the last update of CPU to the present
Total CPU time used by TIME processes (in seconds)
Total CPU time used by the m TIME+ process (in 100s)
Percentage of physical memory used by n% MEM processes
O the total amount of virtual memory used by the VIRT process, in kb. VIRT=SWAP+RES
The size of the virtual memory used by the p SWAP process, in kb.
The amount of unswapped physical memory used by the Q RES process, in kb. RES=CODE+DATA
R the amount of physical memory occupied by CODE executable code, in kb
The amount of physical memory occupied by parts other than the executable code of s DATA (data segment + stack), in kb
T SHR shared memory size (in kb)
Number of page errors in u nFLT
V nDRT the number of pages that have been modified since it was last written.
W / S process status.
D = uninterruptible sleep state
R = run
S = sleep
T = track / stop
Z = zombie process
X COMMAND command name / command line
Y WCHAN displays the name of the system function in sleep if the process is sleeping
"
two。 Use the ps command to view the process
$ps-ef
……
Smx 1822 1 0 11:38? 00:00:49 gnome-terminal
Smx 1823 1822 0 11:38? 00:00:00 gnome-pty-helper
Smx 1824 1822 0 11:38 pts/0 00:00:02 bash
Smx 1827 1 4 11:38? 00:26:28 / usr/lib/firefox-3.6.18/firefox-bin
Smx 1857 1822 0 11:38 pts/1 00:00:00 bash
Smx 1880 1619 0 11:38? 00:00:00 update-notifier
……
Smx 11946 1824 0 21:41 pts/0 00:00:00 ps-ef
Or:
$ps-aux
……
Smx 1822 0.1 0.8 58484 18152? Sl 11:38 0:49 gnome-terminal
Smx 1823 0.0 0.0 1988 712? S 11:38 0:00 gnome-pty-helper
Smx 1824 0.0 0.1 6820 3776 pts/0 Ss 11:38 0:02 bash
Smx 1827 4.3 5.8 398196 119568? Sl 11:38 26:13 / usr/lib/firefox-3.6.18/firefox-bin
Smx 1857 0.0 0.1 6688 3644 pts/1 Ss 11:38 0:00 bash
Smx 1880 0.0 0.6 41536 12620? S 11:38 0:00 update-notifier
……
Smx 11953 0.0 2716 1064 pts/0 R + 21:42 0:00 ps-aux
3. The following shows how to kill a process
At this point, if I want to kill Firefox, the process will be typed on the terminal:
$kill-s 9 1827
Among them,-s 9 establishes that the signal transmitted to the process is 9, that is, to force and terminate the process as soon as possible. Each termination signal and its function are shown in the appendix.
1827 is the PID of Firefox found by ps above.
Simple, but there is a problem, it doesn't matter if there are fewer processes. If there are more processes, you will feel more painful. No matter it is ps-ef or ps-aux, you have to find the process you want to kill in a long list of process information every time.
Advanced chapters:
Improvement 1:
Pipe the query results of ps to grep to find the process that contains a specific string. The pipe character "|" is used to separate two commands, and the output of the command on the left side of the pipe character is used as the input of the command on the right side of the pipe character.
$ps-ef | grep firefox
Smx 1827 1 4 11:38? 00:27:33 / usr/lib/firefox-3.6.18/firefox-bin
Smx 12029 1824 0 21:54 pts/0 00:00:00 grep-color=auto firefox
It will be refreshing this time. And then there is.
$kill-s 9 1827
Or is it too much typing?
Improved 2mi-using pgrep:
What's the first thing that comes to mind when you see pgrep? That's right, grep! The p of pgrep indicates that this command is a grep dedicated to process queries.
$pgrep firefox
1827
What do you see? Yes, the PID of Firefox, and then I'm going to type again:
$kill-s 9 1827
Improved 3mure-using pidof:
What do you think when you see pidof? That's right, pid of xx, which literally translates to xx's PID.
$pidof firefox-bin
1827
A slight disadvantage compared with pgrep is that pidof must give the full name of the process. And then there's the clich é:
$kill-s 9 1827
Whether you use ps and then slowly find the process PID or use grep to find the process containing the corresponding string, or use pgrep to directly find the process PID that contains the corresponding string, and then manually enter it into kill to kill, it is a bit troublesome. Is there a more convenient way? Yes!
Improvement 4:
$ps-ef | grep firefox | grep-v grep | cut-c 9-15 | xargs kill-s 9
Description:
The output of "grep firefox" is all processes with the keyword "firefox".
"grep-v grep" is a process that removes the keyword "grep" from the listed processes.
"cut-c 9-15" intercepts the 9th to 15th characters of the input line, and this happens to be the process number PID.
The xargs command in "xargs kill-s 9" is used to take the output of the previous command (PID) as an argument to the "kill-s 9" command and execute the command. "kill-s 9" forcibly kills the specified process.
Don't you want to complain about something? Yeah, it's too long.
Improvement 5:
Why do you have to play such a long string when you know the two commands of pgrep and pidof?
$pgrep firefox | xargs kill-s 9
Improvement 6:
$ps-ef | grep firefox | awk'{print $2}'| xargs kill-9
Kill: No such process
There is a more depressing place, the process has been correctly found and terminated, but the completion of the execution indicates that the process cannot be found.
The function of awk'{print $2}'is to print the contents of the second column. From the regular article, you can see that the second column of the ps output happens to be PID. Pass the corresponding PID of the process to kill through xargs as a parameter to kill the corresponding process.
Improvement 7:
Do I have to call xargs every time to pass PID to kill? The answer is no:
$kill-s 9 `ps-aux | grep firefox | awk'{print $2}'`
Improvement 8:
Yes, the command is still a little long. Replace it with pgrep.
$kill-s 9 `pgrep firefox`
Improve 9--pkill:
What do you think of when you see pkill? Yes, pgrep and kill! Pkill=pgrep+kill .
$pkill-9 firefox
Note: "- 9" that is, the signal sent is 9. The difference between kill and pkill at this point is that pkill does not need "s", and the termination signal level is directly followed by "-". I always thought it was "- s 9", but each run failed to terminate the process.
Improve 10--killall:
Killall and pkill are similar, but if the process name given is incomplete, killall will report an error. Pkill or pgrep can terminate a process as long as part of the process name is given.
$killall-9 firefox
This is the end of "how linux views a process and kills process ps grep kill". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.