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:
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:
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!