Linux ps command usage Detailed

In Linux, run a program called an instance of the process. Sometimes, while working on a Linux machine, you may need to find processes that are currently running.

There are many commands can help you to find the information of running processes, but ps and top are most commonly used.

In this article, we will discuss how to use the ps command to list currently running processes and displays information about the processes in Linux.

How to use the ps command

The general syntax of the ps command is as follows:

ps [OPTIONS]

For historical and compatibility reasons, the ps command accepts several different types of options:

  • UNIX-style options, there is a dash in front.
  • BSD style options, without having to dash to use.
  • GNU long options, there are two dashes in front.

All types of options can be mixed, but conflicts may occur in some special cases, it is best to stick with one of the options. You can group and BSD UNIX options.

Use it without any options is the simplest form, ps will print four information for a minimum of two processes running in the current shell, shell itself and the processes running in the shell when the command.

ps

The output includes about shell (bash) and processes (ps you type commands) to run in this shell of information:

  PID TTY          TIME CMD
 1809 pts/0    00:00:00 bash
 2043 pts/0    00:00:00 ps

Four marks PID, TTY, TIME, and CMD.

  • PID - the process ID. In most cases, when you run the ps command, the most important information the user is looking for process PID. Learn PID can eliminate the fault process.
  • TTY - Process Control name of the terminal.
  • TIME - Cumulative CPU time for the process, is displayed in minutes and seconds.
  • CMD - name of the command used to start the process.

The output above is not very useful, because it does not contain too much information. When other option is enabled, the real power of the ps command came.

The ps command has a lot of parameters and options can be used to display a specific set of processes and different information about the process, but only a small amount option in daily use.

ps The most commonly used combination of the following options:

BSD table :

ps aux
  • This option tells ps a show processes from all users, in addition to process those not associated with the terminal processes and headed.
  • Representative of u, which provides detailed information about the process of user-oriented format.
  • The x ps option listed in the process without a control terminal. These are mainly the boot process and run in the background at startup.

This command displays the mark 11 columns of information USER, PID,% CPU,% MEM, VSZ, RSS, STAT, START, TTY, TIME, and CMD in.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.8  77616  8604 ?        Ss   19:47   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    19:47   0:00 [kthreadd]
...

We have explained that PID, TTY, TIME and CMD label. The following is a description of other labels:

  • USER - the user running the process.
  • % CPU- process cpu utilization.
  • % MEM - process resident set size accounted for a percentage of the physical memory of the computer.
  • Virtual memory size KiB process - VSZ.
  • The size of the physical memory RSS- process is using.
  • STAT- process status code may be Z (zombies), S (sleep), R (run) and the like ..
  • START - command start time.

To print the process tree, add the f option. This tells ps displays a tree view of the parent to the child process.

ps auxf

The ps command also allows you to sort the output. For example, to sort the output based on memory usage you will use:

ps aux --sort = -% mem

UNIX form :

ps -if
  • The e option tells ps to display all processes.
  • The f station full format listing provides detailed information about the process.

This command information is displayed 7 UID, PID, PPID, C, STIME, TIME and CMD labeled.

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 19:47 ?        00:00:01 /sbin/init
root         2     0  0 19:47 ?        00:00:00 [kthreadd]
...

The label has not been explained have the following meanings:

  • UID- the user with USER run the same process.
  • PPID - ID of the parent process.
  • C-% CPU process with the same cpu utilization.
  • When you start with the same STIME- START command.

To view only certain users to run as a process, use the following command, where linuxize is the name of the user:

ps -f -U linuxize are linuxize

User-defined format

Which column shows the o option allows you to specify run the ps command.

For example, to print only the information related to the PID, COMMAND you will run one of the following commands:

ps -efo pid, comm
ps auxo pid , comm 

And other commands a ps command

the ps command can be used by a pipeline and other commands.

If you want to display the output of the ps command, one page at a time pipe it to the less command:

If you do not want to show too much of a ps output, and less with the use of command

 console-bash ps -ef  | less

The output of the ps command can also be used grep command to filter the results, such as to output only the root user process, the following command can be used

 console-bash ps -ef  |  grep root

to sum up

In solving problems on a Linux system, ps command is one of the most commonly used commands. It has a lot of options, but generally, most users use ps aux or ps -ef collect information about the processes that are running.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159959.htm