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?
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.
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).
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With