To get process name OR command name using process id.
For example I want to find out the command name or process name for the process id 16874
>> ps ax -o pid,cmd | grep 16874 | grep -v grep | cut -d " " -f2-
1 2 3 4
output :
>> /usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
Explanation:
1) To get the list of PIDs and relevant commands:
>> ps ax -o pid,cmd
>>
PID CMD
1 init [3]
2 [migration/0]
3 [ksoftirqd/0]
4 [migration/1]
5 [ksoftirqd/1]
6 [events/0]
7 [events/1]
8 [khelper]
9 [kacpid]
33 [kblockd/0]
2465 /usr/sbin/snmpd -u nobody -g nobody -I -smux -Lsd -Lf /dev/null -p /var/run/snmpd.pid
2511 /usr/sbin/automount --timeout=600 /mnt file /etc/auto.mnt
2525 /usr/sbin/smartd
2534 /usr/sbin/acpid
2552 /usr/sbin/sshd-2222 -f /etc/ssh/sshd_config.2222
16874 /usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
2) To filter for required PID (16874)
>>ps ax -o pid,cmd | grep 16874
>>
552 grep 16874
16874 /usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
3) To remove the grep command line
>> ps ax -o pid,cmd | grep 16874 | grep -v grep
>>
16874 /usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
4) To extract the exact command line
>> ps ax -o pid,cmd | grep 16874 | grep -v grep | cut -d " " -f2-
>>
/usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
/usr/local/bin/perl -w /home/y/bin/yroot hdfs_proxy --user dkuldeep
No comments:
Post a Comment