How to tell if a process was started but crashed in Linux
Consider the following situation: - I am using Linux. I have doubts that my application has crashed. I have not enabled kernel dump. There is no information in the log.
How can I be sure that after a system reboot my application was started, but now it doesn't work because it crashed.
My application is configured as a service written in C / C ++.
In a sense: how can I get all the names of the processes / services that have been running since the system was started? Is it possible?
I know I can turn on logging and start the process again to get the crash.
a source to share
The standard practice is to have a pid file for your daemon (/var/run/$NAME.pid) where you can find your process ID without having to manually parse the process tree. You can then check the status of this process, or have your daemon respond to a signal (usually SIGHUP) and report its status. It's a good idea to make sure that pid is still owned by your process, and the easiest way is to check / proc / $ PID / cmdline.
Appendix: If you are only using new federation or ubuntu your init upstart system which has built-in monitoring and launching capabilities.
As @ emg-2 pointed out, BSD process accounting is available, but I don't think this is the right approach for this situation.
a source to share
Daemons should always: 1) Write the currently running instance process to / var / run / $ NAME.pid using getpid () (man getpid) or an equivalent command for your language. 2) Write a standard log file to / var / log / $ NAME.log (large log files should be split into .0.log for current logs along with .X.log.gz for other logs where X is a number with more low, more recent) 3) / Must / have an LSB compliant start script accepting at least a start stop and restart status. The status can be used to check if the daemon is working.
a source to share
If your application crashed, this is no different from "your application has never started" if your application does not write to the system log. syslog(3)
- your friend.
To find your application, you can try a few ideas:
- Look in the filesystem
/proc
- Run the command
ps
- Try
killall appname -0
and check the return code
a source to share