Linux Tutorial - Process View
Linux is a multi-user system, sometimes it is necessary to understand what other users do, so they will also contact multiple users in this section.
content. At the same time, Linux is a multi-process system, often needs to provide some allocation and management of these processes; and management, first
The process of the road now: What is the process? How is the process? and many more. So you need a process to see the work.
WHO command
This command is primarily used to see the current online user situation. This command is very useful. If the user wants to build a time with other users
Communication, such as using the Talk command, then first determined that the user is indeed online, otherwise the Talk process cannot be established.
As another example, the system administrator wants to monitor each login user, and the WHO command should be used at this moment.
The common syntax format of the who command is as follows:
WHO [IMQSUWHT] [--count] [--der] [--heading] [--help] [--MESSAG] [--MESG] [--Version]
[--WRITABLE] [file] [am i]
All options are optional, that is, the WHO command can be used alone. When do not use any options, the who command will display the following three contents:
Login Name: Log in to the username;
Terminal Line: Using a terminal device;
Login Time: Log in to the system.
If two non-option parameters are given, the who command will only display the username of running the WHO program, log in to the terminal and login time.
Usually these two parameters are "AM I", that is, the format of "WHO AM I".
The usual parameters of the WHO command will be described below.
-m and "WHO AM I", display the username of running the program.
-q, - count only shows the user's login account and the number of logged in users, which is higher than any other option.
-S ignore. Mainly compatible with other versions of the WHO command.
-i, -u, - iDLE shows that the user will operate in the last time, that is, often
"Time" time. Among them, "." The symbol represents the user in the first 1 second; "OLD" means that the user is idle
More than 24 hours.
-H, - Heading shows a ranks of the title. The common titles are shown in Table 4-2.
Table 4-2 WHO command output common title
Title
User user login account
Line user login usage terminal
Login-Time user login time
IDLE user free 洌 童 童 鞯 鞯?
PID user logs in to the shell process ID
FROM user network address
-w, -t - MESG, - Message, - Writable and -s option, display a character after the login account is displayed
Information status:
: Allow write information;
-: Do not write information;
?: You cannot find a terminal device.
- Help Displays help information on standard output.
--Version displays version information on standard output.
Some basic usage of the WHO command is described below.
If you need to see which users do in the system, you can use the who command directly.
[Example 17] View users who log in to the system
$ WHO
Root TTY1 Mar 17 13:49
Foxy TTY2 Mar 17 13:49
Root Tty3 Mar 17 13:49
BBS TTYP0 Mar 17 13:49 (River.net)
It can be seen that there are now four users. In general, this can understand the approximate cases of login users. But sometimes the above display is not so intuitive, because there is no title description, it is not easy to understand, then you need to use the -H option.
[Example 18] View the details of the login user, type:
$ WHO -UH
The display is as follows:
User line login-time iDLE from
Root TTY1 Mar 17 13:49.
Foxy TTY2 Mar 17 13:49 00:01
Root tty3 mar 17 13:49 00:01
BBS TTYP0 Mar 17 13:49 00:01 (River.net)
Such a look at it. Where -u option specifies that the user's idle time is displayed, it can be seen more than one idle. The first root user IDLE item
It is a ".", Which means that the user is still active in 1 second, while other users have a time, called idle time.
Finally, look at the results of using the "WHO AM I" format:
233.River.net! Root tty1 mar 17 13:49
It can be seen that only user situations running the who command, of course, there is no free time at this time.
The WHO command is very simple and can be used to accurately grasp the user's situation, so it is very extensive.
w command
This command is also used to display the user's situation that is logged in to the system, but is different from the who, the W command function is more powerful, but it can not only display
Who is logged in to the system, but also shows the work currently on, and the statistics are more detailed and detailed relative to the WHO command.
Learn, you can think that the w command is a enhancement version of the who command.
The display item of the W command is arranged in the order: current time, system starts to the current time, log in to the number of users, the system is in the most
Nearly 1 second, 5 seconds and 15 seconds average load. Then the data of each user, the order of the project is as follows: log in to the account, the terminal name, far
Cheng host name, login time, idle time, JCPU, PCPU, is currently running the process line.
Where JCPU time refers to all processes that are connected to the terminal (TTY). This time does not include past background homework
Time, but it includes the time occupied by the current running background job. The PCPU time refers to the current process (that is, the process shown in the what item)
The time occupied. The specific usage and parameters of this command are described below.
The syntax format is as follows:
W - [husfv] [user]
The following will be described below:
-H does not display the title.
-u ignores the username when the current process and the CPU time are listed. This is mainly used to perform the case after the su command.
-s use short mode. No login time, JCPU, and PCPU time.
-f switching display from item, which is the remote host name. The default value is not displayed remote host name, of course, system administrators can sources
Do some modifications make it a default value to display this item.
-V Displays version information.
User only shows the relevant cases of the specified user.
[Example 19] Shows the details of the user currently logged in to the system
$ w
2:50 PM Up 2 min, 4 users, Load average: 0.22, 0.16, 0.06
User Tty from login @ idle jcpu pcpu what
Root TTY1 2:49 PM 0: 00S 0.56S 0.10s W
Foxy TTY2 2:49 PM 1:09 0.42S 0.42S Bash
Root TTY3 2:49 PM 46.00S 0.67S 0.25S Telnet BBS3
BBS TTYP0 RIVER.NET 2:49 PM 45.00S 0.49S 0.49s BBS H River.netps Command
1. Introduction to PS
The two commands described above are used to see the current system user, let's take a look at the process of the process, which is the theme of this chapter.
To monitor and control the process, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic.
It is also very powerful process to view commands. Use this command to determine which processes are running and running, whether the process ends,
There is no zombie in the process, which processes take up too much resources. In summary, all information can be obtained by executing the command.
2. PS command and its parameters
The PS command is most commonly used to monitor the work of the background process, because the background process is not with the screen keyboard for these standard input / output
If you are in communication, you can use the PS command if you need to detect it.
The command syntax format is as follows:
PS [option]
The command option is described below:
-e Displays all processes.
-f full format.
-H does not display the title.
-l long format.
-w wide output.
A Displays all processes on the terminal, including processes for other users.
R shows only the running process.
x Displays the process without the control terminal.
O [ | -] K1 [, [ | -] K2 [, ...]] According to the shortcut order specified in the shortcut button, the multi-stage sort order specified in the shortcut key is displayed.
There is a default order specified for different formats of PS. These default order can be overwritten by the user's designation. Among them, " " characters are optional.
The "-" character is the direction of the reverse specified key.
PIDS only lists the 觥 觥 觥 觥 分 分 分 分 分 分 分 分 分 分 分 分The process list must be on the last option of the command line parameter
The back is given, and the space cannot be inserted in the middle. For example: PS -F1, 4, 5.
The following describes the long command line options, these options start: - ":
--Sort x [ | -] Key [, [ | -] Key [, ...]] selects a multi-letter key from the Sort Keys section. " " Characters are optional, because
The default direction is to press digital ascending or dictionary order. For example: ps -jax -sort = uid, -ppid, pid.
--help displays help information.
--Version displays the version information of the command.
The sort button is mentioned in the previous option description, and next, the sort button is further explained. It should be noted that the value used in the sort is PS
The internal value used is not only used for some pseudo values in some output formats. The list of sort keys is shown in Table 4-3.
Table 4-3 Sort key list
Short format long format
C CMD executable simple name
C cmdline full command line
f Flags long pattern sign
Group ID of G PGRP Process
G TPGID Control TTY Process Group ID
J Cutime Cumulative User Time
J CSTIME Cumulative System Time
K uTime user time
K STIME system time
M min_flt times Error number
M maj_flt main page error quantity
N cmin_flt accumulated secondary page error
N cmaj_flt accumulated major page error
o session dialog ID
P PPID process ID
P ppid parent process ID
R RSS resides
R Resident resides
s size memory size (kilobytes)
SHARE sharing page quantity
T Tty TTY secondary device number
Time of the T start_time process started
U uid uid
u User username
v vsize's total virtual memory quantity (bytes)
y priority scheduling priority
3. Common PS command parameters
The parameters introduced in front of the front may make readers feel somewhat terrible. In fact, this is a very easy to use, general users only
It is possible to master some of the most common command parameters.
The most commonly used three parameters are U, A, X, which will be described below to illustrate their specific usage.
[Example 20] Log in to the system as a root to view the current process status
$ PS
PID TTY TIME COMMAND
5800 TTYP0 00:00:00 Bash
5835 TTYP0 00:00:00 PS
It can be seen that the displayed item is divided into four items, which is PID (process ID), TTY (terminal name), Time (process execution time)
Command (the command line input of the process).
You can use the u option to view the process owner and some other details, as shown below:
$ PS U
User PID% CPU% MEM USZ RSS TTY Stat Start Time Command
TEST 5800 0.0 0.4 1892 1040 TTYP0 S NOV27 0:00 -Bash
TEST 5836 0.0 0.3 2528 856 TTYP0 R NOV27 0:00 PS U
There is a horizontal line in front of the Bash process, meaning that the process is the user's login shell, so for a sign-in user into the short horizontal line.
The process is only one. You can also see the% CPU,% MEM two options, the former refers to the percentage of the CPU time and total time occupied by the process; the latter refers to the process
The percentage of memory and total memory occupied.
In this case, all the processes of all control terminals are seen; however, for other processes that do not control terminals, this
You need to use the X option. All processes are observed using the X option.