Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is it possible to find the command line of a running process with its pid? the output of /proc/pid/cmdline seems that it removes the space character to it is hard to read the output.

share|improve this question

3 Answers 3

up vote 10 down vote accepted

From: http://stackoverflow.com/questions/993452/splitting-proc-cmdline-arguments-with-spaces

  1. cat /proc/PID/cmdline | tr '\000' ' '

  2. cat /proc/PID/cmdline | xargs -0 echo

share|improve this answer

ps can show this:

ps -o cmd fp <PID>

ps can do a lot more. For infos, see man ps

share|improve this answer

Put this script in your .bashrc file and source it

$ source ~/.bashrc

You can invoke it with command $pid which takes PIDs as command line argument and gives process name, user(process owner) as ouput eg:

$ pid 1 2 3 4 5 6 7 8 9 10
PID=1  Command=systemd  User=root
PID=2  Command=kthreadd  User=root
PID=3  Command=ksoftirqd/0  User=root
PID=5  Command=kworker/0:0H  User=root
PID=7  Command=rcu_sched  User=root
PID=8  Command=rcu_bh  User=root
PID=9  Command=migration/0  User=root
PID=10  Command=watchdog/0  User=root


function pid(){
        if [[ $# > 0 ]]
                for i in $@
                        ps -e -o pid,comm,user | awk '{print "PID="$1, " Command="$2," User="$3}'| egrep --color "^PID=$i\W"
                echo "Syntax: pid <pid number> [<pid number>]"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.