I have maintained a list of PIDs of processes currently running on my system (Linux). From this, now it would be great if I could get the process details from this PID. I have come over syscall.Getrusage() in Go, but I am not getting the desired results.
What should I do?
The ps -p <PID> command is pretty straightforward to get the process information of a PID. Alternatively, we can also access the special /proc/PID directory to retrieve process information.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
This might not be exactly what the asker wanted (there's not much clear info on what type of details are required for each process id), but you can get some details of a task by its pid using the BASH command ps -p $PID
(ps being short for process status)
With default options as ps -p $PID
this returns:
java
)More information about this process id can be shown using the -o options flag. For a list, see this documentation page.
Here's one example that tells you a particular process PID's full command with arguments, user, group and memory usage (note how the multiple -o flags each take a pair, and how the command outputs with lots of whitespace padding):
ps -p $PID -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS
Tip: for human-read output in the console, make args the last option - it'll usually be the longest and might get cut short otherwise.
Just type this and you will get what you want. Replace 'type_PID_here' with the PID.
cat /proc/type_PID_here/status
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With