Home  >  Article  >  Backend Development  >  How to Get Comprehensive Process Details from its PID in Linux?

How to Get Comprehensive Process Details from its PID in Linux?

Susan Sarandon
Susan SarandonOriginal
2024-11-16 10:55:03901browse

How to Get Comprehensive Process Details from its PID in Linux?

Get Process Details from its PID

In Linux systems, maintaining a list of PIDs for running processes is common. However, extracting detailed information about these processes using syscall.Getrusage() may not yield satisfactory results.

For a comprehensive method, consider utilizing the BASH command ps -p $PID. This command reveals valuable process attributes:

  • PID: The process's unique identifier.
  • TTY: The controlling terminal, if present.
  • TIME: The CPU time consumed since execution (e.g., "00:00:02").
  • CMD: The command that initiated the process (e.g., "java").

To obtain more specific information, employ the -o options flag. The documentation page provides a complete list of available options.

For instance, to display the following details:

  • PID
  • Memory usage (VSZ)
  • User
  • Group
  • Full command with arguments

Use the following command:

ps -p $PID -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS

Note the multiple -o flags with their respective pairs. The memory usage is obtained with vsz=MEMORY, and the full command is extracted with comm,args=ARGS.

For better readability in the console output, place the args=ARGS option last, as it is often the longest and may get truncated otherwise.

The above is the detailed content of How to Get Comprehensive Process Details from its PID in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn