Question

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.

And also where can I find the source code for any linux services. e.g. /etc.init.d/rc5.d/S14cron . It will be helpful in understanding how to implement a service.

Was it helpful?

Solution

The classic reference for this kind of question is Steven's "Advanced Programming in the UNIX Environment". You can find the source code to this text book here.

OTHER TIPS

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.

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top