10 important Linux ps commands

Source: Internet
Author: User

10 important Linux ps commands

As a Unix derivative operating system, Linux has a ps tool for viewing the current process. This tool can be used in the command line.

What is the PS command?

You can see from its man manual that the ps command provides snapshots of processes in the current system. It can capture the Process status of the system in an event. If you want to constantly update the status, you can use the top command.

Ps commands support three syntax formats

  1. UNIX style, options can be combined, and the options must have a hyphen (-)
  2. BSD style. options can be combined, but the options cannot contain hyphens (-).
  3. The GNU-style long option with two "-" hyphens before it.

We can mix these styles, but there may be conflicts. This document uses the UNIX-style ps command. Here are examples of using more ps commands in daily life.

1. Run the ps command without Parameters

This is a basic ps usage. Run this command on the console and view the result.

By default, four columns of information are displayed.

  • PID: The process Number of the running command (CMD)
  • TTY: Location of the command (Terminal)
  • TIME: the CPU processing TIME occupied by the running command
  • CMD: The Command run by the process.

The information is not sorted when it is displayed.

2. display all current processes

Use the-a parameter. -A indicates all. When the x parameter is added, the process that does not control the terminal is displayed.

  1. $ Ps-ax

The result of this command may be very long. For ease of viewing, you can use less commands and pipelines.

  1. $ Ps-ax | less

3. Filter processes by user

You can use the-u parameter to view specific user processes. For example, to view the user's 'pungki' process, run the following command:

  1. $ Ps-u pungki

4. Filter processes by cpu and memory usage

You may want to filter the results by CPU or memory usage, so that you can find the process that occupies your resources. To do this, we can use the aux parameter to display comprehensive information:

  1. $ Ps-aux | less

When the results are very long, we can use pipelines and less commands to filter.

The default result set is not sorted. You can use the -- sort command to sort data.

Sort by CPU usage in ascending order

  1. $ Ps-aux -- sort-pcpu | less

Sort by memory usage in ascending order

  1. $ Ps-aux -- sort-pmem | less

We can also merge them into a command and display the first 10 results in the pipeline:

  1. $ Ps-aux -- sort-pcpu, + pmem | head-n 10
5. Filter by process name and PID

Use the-C parameter, followed by the name of the process you are looking. For example, to display the information of a process named getty, you can use the following command:

  1. $ Ps-C getty

If you want to see more details, you can use the-f parameter to view the formatted Information List:

  1. $ Ps-f-C getty

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.