2

I want to run a c++ program that is using POSIX threads on openSUSE 12 as a daemon, and be able start, stop and restart it as a service with a normal init.d script based on this template: http://www.novell.com/coolsolutions/feature/15380.html.

It turns out however that startproc and killproc are not good for handling kernel threads (which POSIX threads apparently are). I manage to start the program with startproc, but it is not recognized and killed by killproc. The rc_status returns a red "failed" when running startproc even if the program actually is started, and it returns green "done" when running killproc even if it is not killing the process.

Is there an alternative to using startproc/killproc on openSUSE 12? If one starts the service with a simple nohup, how is it then normally stopped? By just killing it? What is in that case a good way of acquiring the pid needed by "kill"?

Johan Lundquist
  • 571
  • 1
  • 5
  • 8
  • Kernel threads to me are "Threads inside the kernel", which isn't what "pthreads" equate to, at least not in my vocabulary. – Mats Petersson Apr 06 '13 at 12:58
  • 1. OpenSUSE 12 has now systemd and you can do it the systemd way: http://0pointer.de/blog/projects/socket-activation.html 2. You need to have a way to shutdown your program cleanly. In the old days it was the signal TERM (SIGTERM). If a program receives such a signal, the signal handler initiates the shutdown, once the program returns from the signal handler it would check for a variable to shutdown, tell it its threads (with a mutex-secured variable for instance) waits for the threads to join and then finally exit itself with exit() or return in main(). – vasquez Apr 06 '13 at 13:01
  • Ok, I got my info from discussions like this one: http://stackoverflow.com/questions/5919896/how-are-posix-threads-implemented-on-linux. And the man page of startproc says: _"Note that startproc is designed to start a daemon but not a kernel thread or a program which enables a kernel thread."_ – Johan Lundquist Apr 06 '13 at 13:09
  • Thank you vasquez! I will look into systemd. – Johan Lundquist Apr 06 '13 at 13:45

0 Answers0