[英]Linux service and Source for cron job
I am new to linux and writing a service in C++ which spawns multiple threads and I am starting the service by calling it from init.d, but how should I send the terminate signal to my application from the script , so that my service terminates all the threads and exits. 我是Linux的新手,并用C ++编写了一个服务,该服务产生了多个线程,我正在通过从init.d调用它来启动该服务,但是我应该如何从脚本向我的应用程序发送终止信号,以便我的服务可以终止所有服务线程和出口。
And also where can I find the source code for any linux services. 而且在哪里可以找到任何linux服务的源代码。 eg /etc.init.d/rc5.d/S14cron .
例如/etc.init.d/rc5.d/S14cron。 It will be helpful in understanding how to implement a service.
这将有助于理解如何实施服务。
Depends what your application does. 取决于您的应用程序做什么。
Personally I'd keep a thread just for handling signals and call sigprocmask in the other threads to stop signals being delivered to them. 我个人将保留一个仅用于处理信号的线程,并在其他线程中调用sigprocmask以停止将信号传递给它们。
The main thread / signal handling thread (it is usually a good idea to make this the main thread) can then send a message to its threads to tell them to finish what they're doing and quit. 然后,主线程/信号处理线程(通常使它成为主线程是一个好主意),然后可以向其线程发送一条消息,以告诉它们完成其操作并退出。
Alternatively, if you like the principle of crash-only, you could just call exit_group and be done with it :) 另外,如果您喜欢仅崩溃的原理,则可以调用exit_group并完成它:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.