I wrote a simple server in C and would like to have the same functionality calling it as other C daemons (such as calling it with ./ftpd start and closing that instance with ./ftpd stop). Obviously the problem I'm having is that I do not know how to grab the current instance of the running program. I can parse the options just fine (using getopt / optarg) but at the moment, ./my-program stop just starts a new instance vs. calling ./my-program start which starts it up fine.
The reason I want to do this is because another program will be signaling my server to stop, so a call like ./my-program stop is very simple, which can then stop the server loops and close all the open fd's. Thanks!
Is it possible to do this in the C program itself or is this usually handled externally?