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.

0


a source to share


8 answers


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.

+5


a source


This feature is included in the Linux kernel. He called it: BSD process accounting.



+6


a source


I would recommend that you write the fact that you started with some kind of log file, either from a private one that gets overwritten on every startup, or via Syslogd .

Plus, you can record a beat of the same name so you know exactly when it crashed.

+2


a source


you can probably make a decoy, that is, an application or shell script that is just a wrapper around the true application, but adds some entries like "Application is running". Then you change the name of your original app and give your original name.

+1


a source


As JimB mentions, you have a daemon PID file. You can determine if it is working or not by sending a signal to it 0

via a system call kill(2)

or program kill(1)

. The return status will tell you if a process exists with this PID.

+1


a source


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.

+1


a source


I don't know of a standard way to get all executable process names; but it can be a way to do this using SystemTap .

If you just want to monitor your process, I would recommend using waitid (man 2 wait) after fork instead of detaching and unmounting.

0


a source


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
0


a source







All Articles