如何知道如果一个程序已经启动,但在Linux中坠毁 [英] How to know if a process had been started but crashed in Linux

查看:177
本文介绍了如何知道如果一个程序已经启动,但在Linux中坠毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下情况: -
我使用Linux操作系统。
我怀疑我的应用程序崩溃。
我没有启用核心转储。
有日志中没有的信息。

Consider the following situation: - I am using Linux. I have doubt that my application has crashed. I had not enabled core dump. There is no information in the log.

怎么能肯定的是,在系统重新启动后,我的应用程序已启动,但现在没有运行,因为它已经崩溃了。

How can I be sure that, after the system restart my app was started, but now it is not running, because it has crashed.

我的应用程序被配置为一个服务,用C / C ++。

My app is configured as a service, written in C/C++.

在一个办法:?我怎么可以得到所有自系统已执行的进程/服务名称开始它甚至有可能

In a way: how can I get all the process/service names that have executed since the system start? Is it even possible?

我知道,我可以启用日志记录并再次启动过程中获得的崩溃。

I know, I can enable logging and start the process again to get the crash.

推荐答案

标准的做法是有你的守护进程(/var/run/$NAME.pid)一个pid文件,在其中你可以找到它的进程ID,而无需手动解析进程树。然后,您可以检查进程的状态,或者使你的守护进程的信号(通常SIGHUP)作出回应,并报告其状态。这是一个好主意,以确保该PID仍属于你的进程也是如此,而最简单的方法就是检查/ proc / $ PID / CMDLINE。

Standard practice is to have a pid file for your daemon (/var/run/$NAME.pid), in which you can find its process id without having to parse the process tree manually. You can then either check the state of that process, or make your daemon respond to a signal (usually SIGHUP), and report its status. It's a good idea to make sure that this pid still belongs to your process too, and the easiest way is to check /proc/$PID/cmdline.

附录:
如果你只使用新的Fedora或Ubuntu,你的初始化系统可以新贵,其中有监控和内置触发功能英寸

Addendum: If you're only using newer fedora or ubuntu, your init system is upstart, which has monitoring and triggering capabilities built in.

作为@ EMG-2所指出的,BSD进程记帐是可用的,但我不认为这是造成这种情况的正确的做法。

As @emg-2 noted, BSD process accounting is available, but I don't think it's the correct approach for this situation.

这篇关于如何知道如果一个程序已经启动,但在Linux中坠毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆