How to find the corresponding command for a existing PID?

Hi All,

A process completed already and I have the PID. I want to know the which command used for this PID. 'ps' command and '/proc' folder having the list current process only. Is there a way to search completed process PID?

Thanks,
Manimuthu

PIDs get recycled, they point to an entry in the process table rather than a specific event.

How did you get the PID of the completed process?

I have a core file and i am trying to analyze with GDB.

I got the below output and want to know about which command used for the PID's

(gdb) core /opt/lampp/var/mysql/core.mysqld.9765
BFD: Warning: /opt/lampp/var/mysql/core.mysqld.9765 is truncated: expected core file size >= 5137190912, found: 104931328.
[New Thread 8600]
[New Thread 21224]
[New Thread 20966]
[New Thread 20961]
[New Thread 20870]
[New Thread 20802]
[New Thread 22497]
[New Thread 29685]
[New Thread 9787]
[New Thread 9786]
[New Thread 9785]
[New Thread 9784]
[New Thread 9783]
[New Thread 9782]
[New Thread 9781]
[New Thread 9780]
[New Thread 9779]
[New Thread 9778]
[New Thread 9776]
[New Thread 9775]
[New Thread 9774]
[New Thread 9773]
[New Thread 9772]
[New Thread 9771]
[New Thread 9770]
[New Thread 9769]
[New Thread 9768]
[New Thread 9767]
[New Thread 9765]
Core was generated by `./mysqld'.
Program terminated with signal 11, Segmentation fault.
#0 0x00000031fac07638 in ?? ()
(gdb)

The process must be running in order to know the process/command name through PID (process ID). If a process completes then the respective /proc/<PID> directory will be removed.

# ps -elf | grep vmstat
0 S root      1724  1705  0  80   0 -  1530 hrtime 10:54 pts/1    00:00:00 vmstat 10
0 S root      1727  1602  0  80   0 - 25810 pipe_w 10:54 pts/0    00:00:00 grep vmstat
# cat /proc/1724/cmdline
vmstat10
# ps -elf | grep vmstat
0 S root      1730  1602  0  80   0 - 25810 pipe_w 10:55 pts/0    00:00:00 grep vmstat
# cat /proc/1724/cmdline
cat: /proc/1724/cmdline: No such file or directory
#

If you can re-create your problem, you can have "ps -elf" command running in a loop to capture the command or process name.

Thanks, I am using redhat linux and i know when the 'core' file was created. Is there any way to check to generic log file, then pls let me know the path.

Not that I am aware of. Please wait for others to respond.