Provision and view of users and processes in Linux

Source: Internet
Author: User

This section describes not only process viewing, but also what other users are doing because Linux is a multi-user system, therefore, this section also involves multiple users. At the same time, Linux is a multi-process system that often requires some deployment and management of these processes. To manage these processes, you must first know the current process: What processes are there? What is the process? And so on. Therefore, you need to view the process.
Who command
This command is used to view the current online users. This command is very useful. If you want to establish instant communication with other users, such as using the talk command, you must first make sure that the user is online. Otherwise, the talk process cannot be established. Another example is that the system administrator also needs to use the who command to monitor what every login user is doing at this moment.
The common syntax format of the WHO command is as follows:
Who [imqsuwht] [-- count] [-- idle] [-- heading] [-- help] [-- message] [-- mesg] [-- version] [-- writable] [file] [am I]
All options are optional, that is, the WHO command can be used independently. If no option is used, the WHO command displays the following three items:
Login Name: logon username;
Terminal line: Use a terminal device;
Login Time: the logon time to the system.
If two optional parameters are provided, the WHO command only displays the user name, logon terminal, and logon time of the WHO program. These two parameters are usually "Am I", that is, the command format is "Who am I ".
The following describes the common parameters of the WHO command.
-M is the same as "Who am I" and displays the user name that runs the program.
-Q, -- count only displays the number of Logon accounts and users. This option takes precedence over other options.
-S ignore. It is mainly used for compatibility with who commands of other versions.
-I,-u, -- idle shows the last time the user has performed the system operation since the logon time, that is, the "Daze" time. The "." symbol indicates that the user is still active in the first second. the "old" symbol indicates that the user has been idle for more than 24 hours.
-H, -- heading displays the title of a row of columns. Common titles are shown in Table 4-2.
Table 4-2 common titles output by the WHO command
Question mark
Description
User
User Logon account
Line
User Logon Terminal
LOGIN-TIME
User Logon Time
Idle
Idle Time of the user, that is, the time when the user is not performing the operation
PID
The process ID of the user to log on to the shell
From
User Network Address
-W,-t -- mesg, -- message, -- writable is the same as the-s option. A character is displayed after the Logon account to indicate the user's information status:
+: Allowed to write information;
-: Information cannot be written;
? : The terminal device cannot be found.
-- Help displays help information on the standard output.
-- Version displays version information on the standard output.
The following describes some basic usage of the WHO command.
If you need to check which users are on the system, you can directly use the who command.
[Example 17] view logon users to the System
$ Who
Root tty1 Mar 17 :49
Foxy tty2 Mar 17 :49
Root tty3 Mar 17 :49
BBS ttyp0 Mar 17 13:49 (river.net)
We can see that there are currently four users in the system. The first column is the logon user's account; the second column is the terminal used for Logon; the third column is the logon time; the fourth column is the network address where the user logs on, and the domain name.
In general, this gives you an overview of the login user. 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] to view the details of a logon user, type:
$ Who-uh
Shown as follows:
User line LOGIN-TIME (idle from)
Root tty1 Mar 17 :49.
Foxy tty2 Mar 17 01
Root tty3 Mar 17 01
BBS ttyp0 Mar 17 (river.net)
This is clear. The "-U" option indicates that the user's idle time is displayed. Therefore, an idle is added. The idle item of the first root user is a ".", which means that the user is still active in the first second, and other users have a time later, called idle time.
Finally, let's take a look at the results of the command in the "Who am I" format:
233.river.net! Root tty1 Mar 17 :49
Only the user running the who command is displayed. Of course, there is no idle time at this time.
The WHO command is very simple to use and can accurately grasp the user's situation, so it is widely used.
W command
This command is also used to display the user login to the system. However, unlike who, the W command is more powerful. It not only shows who has logged on to the system, the current work of these users can also be displayed, and the statistical data is more detailed and scientific than the WHO command. We can think that the W command is an enhanced version of the WHO command.
The display items of the W command are arranged in the following order: current time, system start time, number of logged-on users, average load of the system in the last 1 s, 5 S, and 15 s. The data of each user is displayed in the following order: Logon account, terminal name, remote host name, Logon Time, idle time, jcpu, pcpu, and command line of the currently running process.
The jcpu time refers to the time occupied by all processes connected to the terminal (TTY. This time does not include the previous background job time, but includes the time occupied by the currently running background job. The pcpu time refers to the time occupied by the current process (that is, the process displayed in what. The following describes the specific usage and parameters of the command.
The syntax format is as follows:
W-[husfv] [user]
Parameters are described as follows:
-H does not display the title.
-U ignores the user name when listing the current process and CPU time. This is mainly used after the su command is executed.
-S uses the short mode. The logon time, jcpu, and pcpu time are not displayed.
-F: indicates the from entry, that is, the remote host name. The default value is that the remote host name is not displayed. Of course, the system administrator can make some modifications to the source file so that the displayed option becomes the default value.
-V displays the version information.
User Only displays information about the specified user.
[Example 19] displays the details of the user currently logged on to the system.
$ W
PM up 2 min, 4 Users, load average: 0.22, 0.16, 0.06
User tty from login @ idle jcpu pcpu what
Root tty1 PM 0: 00 s 0.56 s 0.10 S W
Foxy tty2 PM 0.42 s 0.42 s bash
Root tty3 PM 46.00 s 0.67 s 0.25 s Telnet bbs3
BBS ttyp0 river.net PM 45.00 s 0.49 s 0.49 s bbs h river.net
Ps command
1. PS Overview
The two commands described above are used to view the current system user situation. The following describes the process situation, which is also the topic of this chapter. To monitor and control processes, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic and very powerful process viewing command. You can use this command to determine which processes are running and running, whether the process is terminated, whether the process is dead, and which processes are occupying excessive resources. In short, most of the information can be obtained by executing this command.
2. ps command and its parameters
The most common ps command is used to monitor the working conditions of background processes, because background processes do not communicate with standard input/output devices such as the screen keyboard, so if you need to detect the situation, you can use the ps command.
The syntax of this command is as follows:
PS [Option]
The following describes the Command Options:
-E: displays all processes.
-F full format.
-H does not display the title.
-L long format.
-W width output.
A displays all processes on the terminal, including those of other users.
R only displays running processes.
X shows the process without any control terminal.
O [+ |-] K1 [, [+ |-] K2 [,…] The process list is displayed based on the multilevel sorting sequence specified by the shortcut keys in short keys, K1, and K2. The default sequence is specified for different PS formats. The default sequence can be overwritten by the user's specified sequence. The "+" character is optional, and the "-" character is used to reverse the direction of the specified key.
PIDs only lists the conditions of the specified process. Process IDs are separated by commas. The process list must be followed by the last option of the command line parameter. spaces cannot be inserted in the middle. For example, PS-F1, 4, 5.
The following describes the long command line options, all of which start:
-- Sort X [+ |-] Key [, [+ |-] Key [,…] Select a multiple keys from the sort keys segment. The "+" character is optional, because the default direction is in ascending order of numbers 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 key is mentioned in the preceding option description, and further describes the sort key. Note that the values used in sorting are internal values used by PS, not only pseudo values in some output formats. The sorting Key List is shown in Table 4-3.
Table 4-3 sorting Key List
Short format
Long format
Description
C
CMD
Simple executable name
C
Cmdline
Complete command line
F
Flags
Long MODE flag
G
Pgrp
Group ID of the process
G
Tpgid
Control tty Process Group ID
J
Cutime
Cumulative user time
J
Cstime
Accumulative system time
K
Utime
User time
K
Stime
System time
M
Min_flt
Number of secondary page errors
M
Maj_flt
Number of major page errors
N
Cmin_flt
Accumulative secondary page Error
N
Cmaj_flt
Accumulative Main Page Error
O
Session
Dialog ID
P
PID
Process ID
P
Ppid
Parent process ID
R
RSS
Resident size
R
Resident
Resident page
S
Size
Memory size (kilobytes)
S
Share
Number of shared pages
T
Tty
Tty secondary device number
T
Start_time
Process start time
U
UID
UID
U
User
User Name
V
Vsize
Total number of virtual memory (bytes)
Y
Priority
Kernel scheduling priority

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.