在c / c ++中运行级别更改时执行代码 [英] Execute code at runlevel change in c/c++

查看:76
本文介绍了在c / c ++中运行级别更改时执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在java中创建一个使用某些c / c ++代码的应用程序,以便在计算机关闭,重启,休眠,睡眠或注销之前执行某些代码。我在java论坛上被告知我必须使用c / c ++编码才能做到这一点。我想知道在我的c / c ++应用程序中的终端中使用命令运行级别是否足够,如果返回了某些内容,那么我会将其发送到我的java应用程序,以完成剩下的工作。如果这还不够,有人可以给我一个关于我如何解决问题的建议吗?

谢谢。

I am trying to make an app in java that uses some c/c++ code in order to execute some code before computer shutdown,restart,hibernate,sleep or logoff. I was told in the java forum that I had to use c/c++ coding to do this. I was wondering if it would be enough to use the command runlevel in a terminal in my c/c++ app, and if that returns something, then I would send that to my java app, to do the rest. If this is not enough, could someone give me a suggestion as to how I could solve my problem?
Thanks.

推荐答案

没有不是你被告知的。我所说的是你需要知道Linux是否提供了一种向应用程序发送消息的机制,告知它正在关闭它。
No that is not what you were told. What I said was that you need to find out if Linux provides a mechanism for sending messages to applications to inform them that it is shutting down.


我发现你可以在linux中使用信号,在ac / c ++应用程序中接收该消息。根据我的理解,当应用程序终止时会使用信号sigterm,因此我认为它将用于重启,关闭和注销,因为单击这些按钮时会终止所有应用程序。

我想知道的是当计算机进入休眠或睡眠状态时发送的信号是什么?
I found out that you can use signals in linux, to receive that message in a c/c++ app. From what I understand, the signal sigterm is used when the application is terminated, so from what I think, it would be used in restart, shutdown, and logoff, since all the applications are terminated when these buttons are clicked.
What I would like to know is what signal is sent when the computer goes to hibernate or sleep?


这篇关于在c / c ++中运行级别更改时执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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