What commands are used to view processes under linux
Commands that can be used to view processes under linux:
1. ps command to find the PID number associated with a process:
2. psa displays all programs under the current terminal, including other users’ programs.
3. ps-A displays all programs.
4. psc lists programs by displaying the true command name of each program without paths, parameters, or labels for resident services.
5. ps-e This parameter has the same effect as specifying the “A” parameter.
6. pse lists the programs and displays the environment variables used by each program.
7. psf uses ASCII characters to display a tree structure that expresses the interrelationships between programs.
8. ps-H displays a tree structure that expresses the interrelationships between programs.
9. ps-N displays all programs except those under the terminal that executes the ps command.
10. pss displays the status of programs using the program signal format.
11. psS lists the program including information on interrupted subroutines.
12. ps-t<Terminal number> specifies the terminal number and lists the status of programs belonging to that terminal.
13. psu displays the status of programs in a user-oriented format.
14. psx displays all programs without distinguishing them by terminal.
Examples of using the ps process view command in Linux
Examples of using the ps process view command in Linux
Examples of using the ps process view command in Linux
The ps command in linux is an abbreviation for ProcessStatus. ps lists the processes currently running on the system, and the processes listed are the ones that are running at the moment the ps command is executed.
To display process information dynamically, you need to use the top command.
With the ps command, you can determine which processes are running and in what state, whether they are terminated, whether they are dead, and which ones are taking up too many resources.
To kill a process, use the kill command, example: kill12345 (12345 is the pid of the process)
Linux processes have five states
1. running (running or waiting in the run queue)
2. interrupted (in hibernation, blocked, or waiting for a certain condition to be formed or signal to be received)
3. p>
3. Uninterruptible (signal received does not wake up and is not runnable, the process must wait until an interrupt occurs)
4. Frozen (the process is terminated, but the process descriptor exists until it is released by the parent process by calling the wait4() system call)
5. Stopped (the process stopped running after being signaled by the SIGSTOP, SIGSTP, SIGTIN, SIGTOU signals)
5. SIGTOU signals to stop running)
psThe identifiers for the five process states are as follows:
R running runnable(onrunqueue)
S interruptible sleeping
D uninterruptible uninterruptiblesleep(usuallyIO)
Z stiff adefunct(“zombie”) process
T stopped tracerstopped
Command parameters
a show all processes
-a show all programs under the same terminal
-A show all processes
c show the processes’ real names
-N reverse selection
-e equals “-A”
e displays environment variables
f displays relationships between programs
-H displays the tree structure
r displays the processes in the current terminal
T displays All programs on the current terminal
uAll processes for the specified user
-auDisplay more detailed information
-auxDisplay all processes containing other users
-Command lists the status of the specified command
-linesNumber of linesDisplay number of lines per page
-widthCount of characters per page
-helpDisplays help information
-versionDisplays the version display
Meaning of the output columns
F stands for the flag of the program,4 represents the user as superuser
S represents the state (STAT) of this program, the meaning of each STAT will be described in the inner text
UID program is owned by this UID
PID process ID
PPID is the ID of the parent program
Resource used by CCPU Percentage
PRI is an abbreviation for Priority, which is described in more detail later
NI is a Nice value, which we’ll continue to describe in the next subsection
ADDR is a kernelfunction, which indicates what part of memory the program is in. If it’s a running program, it’s usually “-“
SZSize of memory used
WCHANWhether the program is currently running or not, if it’s – it means it’s running
TTTYTerminal location of the logger
TIME The amount of CPU time used.
Commands issued by CMD
Examples:
1. Show all processes
The code is as follows:
fdipzone@ubuntu:~$ps-A
PIDTTYTIMECMD
1?00:00:01 init
2?00:00:00
2? p>2?00:00:00kthreadd
3?00:00:00ksoftirqd/0
4?00:00:00kworker/0:0
5?00:00:00kworker/u:0
6?00:00:00migration /0
7?00:00:00migration/1
8?00:00:00kworker/1:0
9?00:00:00ksoftirqd/1
10?00:00:00kworker/0:1
… Omit some results
2. Show specified user processes
The code is as follows:
fdipzone@ubuntu:~$ps-ufdipzone
PIDTTYTIMECMD
1502?00:00:00gnome-keyring-d
1521?00:00:00 gnome-session
1551?00:00:00 ibus-daemon
1555?00:00:00 ssh-agent
1558?00:00:00 dbus-launch
1559?00:00:00 ibus-gconf
1561?00:00:00 python
1563?00:00:00 dbus-daemon
1564?00:00:00 ibus-x11
1569?00:00. 00gconfd-2
… Omit some of the results
3. Show all processes and display the command line
The code is as follows:
fdipzone@ubuntu:~$ps-ef
UIDPIDPPIDCSTIMETTYTIMECMD
root10022:53?00:00:. 01/sbin/init
root20022:53?00:00:00[kthreadd]
root32022:53?00:00:00[ksoftirqd/0]
root42022:53?00:00:00[kworker/0. 0]
root52022:53?00:00:00[kworker/u:0]
root62022:53?00:00:00[migration/0]
root72022:53?00:00:00[migration/1]
< p>root82022:53?00:00:00[kworker/1:0]
root92022:53?00:00:00[ksoftirqd/1]
root102022:53?00:00:00[kworker/0:1]
… Omit some of the results
4. Use in combination with the grep command to find the specified process
The code is as follows:
fdipzone@ubuntu:~$ps-ef|grepapache
root20321022:56?00:00:01/usr/sbin/ apache2-kstart
www-data23182032022:58?00:00:00/usr/sbin/apache2-kstart
www-data23192032022:58?00:00:00/usr/sbin/ apache2-kstart
www-data23202032022:58?00:00:00/usr/sbin/apache2-kstart
www-data23212032022:58?00:00:00/usr/sbin/ apache2-kstart
www-data23222032022:58?00:00:00/usr/sbin/apache2-kstart
www-data23232032022:58?00:00:00/usr/sbin/ apache2-kstart
… Omit some results
5. Show bash-related processes for currently logged-in user
The code is as follows:
fdipzone@ubuntu:~$ps-l
FSUIDPIDPPIDCPRINIADDRSZWCHANTTYTIMECMD
0S1000180517980800-7011waitpts/000:00:00bash
0R1000256118050800-3377-pts/000:00:00ps
6. List all the processes started by the user
The code is as follows:
[ fdipzone@ubuntu:~$psaux
USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND
root10.10.2241362188?Ss22:530:01/sbin/init
root20.00.000?Ss22:530:00[kthreadd]
root30.00.000?Ss22:530:00[ksoftirqd/0]
root50.00.000?Ss22:530:00[kworker/u:0]
root60.00.000?S22:530:00[migration/0]
root70.00.000?S22:530:00[migration/1]
root80.00.000?S22:530:00[kworker/1:0]
< p>root90.00.000?S22:530:00[ksoftirqd/1]
root100.00.000?S22:530:00[kworker/0:1]
root110.00.000?S22:530:00[cpuset]
root120.00.000?S22:530:00[khelper]
… Omit some of the results
Also:
a: show processes started by other users
x: see the processes in the system that belong to you
u: the user who started this process and the time it was started