When user starts the service using the UI and as soon as closes the UI after starting the service, the service also used to get stop. After banging my head against the PC hundred times I got the clue and solution :)..
Reason for the above behavior: the SIGHUP signal
SIGHUP is a signal sent to a process when its controlling terminal ( or parent terminal) is closed. This signal causes all child processes to terminate when the terminal which launched them is closed. In my case, the GUI was launched using a shell script, and when the UI was closed, the shell script gets closed and thus the launched service as well.
Solution : NOHUP
NOHUP is a command to ignore SIGHUP signal, enabling the command to keep running even after the controlling terminal terminates. The nohup syntax :
nohup command-name &
And pufffff.... magic was done
And on the last note, nohup prevents logging so to get logs you must redirect I/O stream to some text file using > indirection
Stay tuned....
No comments:
Post a Comment