I developed an IP messenger using C language and I wish to share some of it's implementation details to make completely understand my problem.
And everything works perfect when i am starting this process from a terminal. But then i created a startup entry for this program to run it as a service, by adding startup script in /etc/init.d/
directory.
then i started my service using the service command,
# service ipmsnger start
Now i can see the process is running by using ps
command. but it does not shows the popup window if a message arrives. message sender gets success delivery report from the messenger. What will be the reason? What is the difference between staring a demon process from terminal by user and starting it as a startup service by system?
When you start your program from a terminal window, it is associated with your current login session. This gives it the context needed to present popups in your GUI.
But remember that Linux is a multiuser system, supporting even multiple concurrent GUI sessions. Each GUI belongs to one session; there isn't any sense of a one true GUI for the machine. If you start your program as a system service then it is not connected with any particular login session, so it does not know about your GUI to present anything there.
Given that the service runs with root privilege, it might be possible for it to discover login sessions and pop up messages in them, but you do not get that for free.
I infer that the point of running your program as a service is to make it usable by people who cannot assert root privilege. In that case, I suggest refactoring into two programs: a service that runs as root, and a client that runs without privilege. Users are expected to run the client, as themselves, in the session where they want to receive popups. The client registers itself with the server. The server receives messages from the network and distributes them to registered clients for them to display.