What I want to know is PIDs that were assigned to a process before its last 2-3 restart.

Scenario is after this particular process crashes, a log file is generated and PID of the process is concatenated to the name of log file. I have such 5 log files with name as hs_err_PIDs. I want to confirm whether these PIDs were assigned to the process I am concerned with, as I am little confused about it.

Is there a way I can do it?


You MAY find this information in the system log files /var/log/messages, /var/log/syslog. Some processes print messages to the system log when it starts. For example, squid prints the following:

May  8 00:00:00 proxy squid[7274]: Squid Parent: child process 28819 started

If your process logs such information, you can know the old PIDs like 7274.

Another possibility is the case when your process causes an error like segfault when it died. You will find a log like this:

May  8 00:00:00 proxy kernel: [1075746.767514] squid[24442]: segfault at 20 ip 00000000005bae26 sp 00007fff144918e0 error 4 in squid[400000+264000]

You can also find the PID in such a log record 24442.

For future cases, you need to log such information if you are interested in finding it later.

  • These files are empty. And I think this logging is controlled at OS level so I am wondering why it didn't happen. I think there is something wrong with machine. I will dig more. Thanks for info! – stillStudent May 8 '12 at 8:06
  • @stillStudent: For starting information (1st case), it is done by the running process. For the segfault (2nd case), it is done by the kernel. – Khaled May 8 '12 at 8:08

Unless the application writes it's PID to a log file then you can't get this information retrospectively. Going forward you could write a wrapper script to start your application and log the PIDs to a file or you could enable accounting.

A simple wrapper might be

yourcommand &
echo $! >>/path/to/pid_history.log

If there is no log entry somewhere of this (made either by the program itself or it's start script), there is no way to get this info, as there is no standard logging of this info.

  • I also doubted that I will get it. Thanks for clearing the doubt! – stillStudent May 8 '12 at 7:29
# ps ax > /tmp/process.list; for i in `seq 1 600`; do echo $i >> /tmp/plog; date >> /tmp/plog; ps ax | diff /tmp/process.list - >> /tmp/plog; sleep 1; done; ping -a

This construction collect difference of process list into the file /tmp/plog in during 10 mins for each sec. After end of logging it will send you a signal from console.

You may add this to the rc.local file for start logging immediately after server starting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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