如何知道一个进程是否已经开始,但在Linux中崩溃 [英] How to know if a process had been started but crashed in Linux

查看:325
本文介绍了如何知道一个进程是否已经开始,但在Linux中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情况: -
我正在使用Linux。
我怀疑我的应用程序已经崩溃了。
我没有启用核心转储。
日志中没有信息。



如何确定系统重新启动后,我的应用程序已启动,但现在没有运行,因为它已经崩溃了。



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



一种方式:如何获取系统启动以来执行的所有进程/服务名称?是否可以?



我知道我可以启用日志记录并重新启动该过程以获得崩溃。

解决方案

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



附录:
如果您只使用较新的fedora或ubuntu,则您的init系统是 upstart ,它具有监视和触发功能内置。



正如@ emg-2所指出的,BSD进程会计可用,但我不认为这是这种情况的正确方法。 p>

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.

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.

解决方案

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.

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

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天全站免登陆