Reputation: 1101
I have two processes. 1) Server and 2) Client. The perquisite for the client to run is that server process must be running. I can do this check my monitoring the output of pidin command. The problem lies when server process dies while the client is running. I(client process) want to be able to get notified if a server process dies and restart the server process.
Can this be achieved in easiest possible way? Does QNX offers any mechanism for this?
PS: I do not want to use the QNX IPC mechanism (like ConnectAttach).
Upvotes: 0
Views: 1369
Reputation: 436
if the server does not daemonize itself then its parent can detect termination via a SIGCHLD handler and waitpid(). A random example is located on this page, among many others: http://www.microhowto.info/howto/reap_zombie_processes_using_a_sigchld_handler.html The parent of the server could provide notification about the termination.
if the server daemonizes itself then anyone can detect its termination via the QNX-specific procmgr_event_notify() API. The following official documentation page provides a complete sample program demonstrating the use of the API: http://www.qnx.com/developers/docs/6.5.0_sp1/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2Fprocmgr_event_notify.html
Not nice style but if you are fine with a quick hack then you may periodically review the list of running processes under /proc. Each numeric directory entry under /proc represents a process with PID=name of directory. The documentation page in (2.) above demonstrates how to get the name (full path of the binary) of the process. If you resort to this method then my recommendation is to find out the pid of the process you are looking for and monitor that pid only later rather than going through the complete list each time. Also note that, in theory, the original process may terminate and the PID get reused between two consecutive checks. If you are currently running pidin and parsing its output then I suggest you use the method described in this entry as this approach involves much less overhead than creating a complete pidin process.
Let me know if you have any questions regarding the above.
Upvotes: 2