Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the reason for a dead process without log file on unix?

This is an interview question.

A developer started a process. But when a customer wants to use the process, he found the process wasn't running. The developer logged in and found the process died. How can the developer know what was wrong?

Follow up: a running process which is supposed to write logs to a file. But there are no logs in the file. How can the developer figure out what's going on in the process?

I think : If the program can be re-run, i will use gdb to track the process. If not, check the output file from the process (the application program). or, add print to the code.

But, are there other ways to do it by referring some information generated by OS?

like image 239
runner frank Avatar asked Oct 27 '11 05:10

runner frank


People also ask

Why is Linux killing my process?

The Linux Kernel may also decide to terminate one or more processes when the system is running low on resources. A very common example of that is the out-of-memory (OOM) killer, which takes action when the system's physical memory is getting exhausted.

How do I find the process log in Linux?

This is such a crucial folder on your Linux systems. Open up a terminal window and issue the command cd /var/log. Now issue the command ls and you will see the logs housed within this directory (Figure 1).

In which log we can check if the running process is killed by kernel?

If the kernel killed a process (because the system ran out of memory), there will be a kernel log message. Check in /var/log/kern.

How do I see sleep processes in Linux?

Just grep -l sleeping /proc/[0-9]*/status and maybe pipe it via | xargs -n1 dirname | xargs -n1 basename or something like that. Looping and checking return value and echo will be very slow. Using { } instead of do done is discouraged - it's a (strange) bash extension, just do done .


1 Answers

If you have the disk space and spare CPU power, you can leave strace following the program to catch the sequence leading up to exit.

One possible cause if the program died without leaving any trace is the Out-Of-Memory (OOM) killer. This will leave a message in the kernel log if it kills your process.

From the same answer, process accounting can be modified to provide some clues by telling you the exit code along with the exit time.

like image 113
Adrian Cox Avatar answered Oct 03 '22 16:10

Adrian Cox