Process status query on Linux

Source: Internet
Author: User
Tags syslog

There are 5 states of processes on Linux:
1. Running (running or waiting in the running queue)
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
3. Non-interruptible (receive signal does not wake up and not run, process must wait until interrupt occurs)
4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running run)

PS Tool identifies 5 status codes for the process:
D non-interruptible uninterruptible sleep (usually IO)
R run runnable (on run queue)
S Interrupt Sleeping
T stop traced or stopped
Z Zombie a defunct ("zombie") process


Note: Other states also include w (no-dwell page), < (high-priority process), N (low-priority process), L (Memory lock page).


You can view the status of a process with the following command
Ps-aux

List programs that resemble the program tree display (shows which sub-processes are under the process)
Ps-axjf

Find PID numbers related to both Cron and syslog services

ps aux | egrep ‘(cron|syslog)‘

You can also use the PS format output to view the status of the process:
Ps-eo User,stat..,cmd


User username
UID User number
PID Process Number
Ppid Parent Process Number
Size memory, Kbytes bytes.
Vsize Total virtual memory size, Bytes bytes (including code+data+stack)
Share Total shared pages
Nice process priority (default = 0, up to-20)
Priority (PRI) kernel scheduling
Percentage of physical memory shared by the PMEM process
TRS program execution code resident size
The total amount of physical memory used by the RSS process, Kbytes bytes
Time process execution up to now total CPU take-up times
Stat process Status
CMD (args) simple format for executing commands


Example:
View the uid,pid,stat,pri of the current system process, sorted by UID number.
Ps-eo Pid,stat,pri,uid--sort UID


View the User,pid,stat,rss,args of the current system process, sorted by RSS.
Ps-eo User,pid,stat,rss,args--sort RSS



Under Linux, there is also a way to check if a process exists: take advantage of the/proc file system. /proc/pid/stat There are process status, process executable file name, etc. if the file does not exist, then the process must have exited. If it exists, you can check the status and file name correctly. Efficiency may be higher than PS, because/proc is a virtual file system that exists in memory.

How to use the/proc file system
Cat/proc/pid/status
Here the PID is your process ID, look at the output, there is a column state

When you want to use the/proc file system, int fd = open ("/proc/pid/status", o_rdonly);
Here the PID is the actual process of the PID, if open fails, the just process obviously does not exist, then read the contents of the file, find the state

Process status query on Linux

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.