Restart a console app

Hi, my console app will be daemonized on launch, with args -d.

I would like to restart or stop the app calling different command like -restart or -stop.
Is there a way to kill the actual instance of app and relaunch a new one?

thanks

platform ?
that really matters here (and you should put your post in the right target section so people know when they see the post)

Right, i’m developing for Raspberry Pi, so linux.

OK so if I understand this right you want to do something like

    cmd>appname -d

and this will start it and daemonize it ?

then later you want to do something like

    cmd>appname -restart

and this will quit it and restart it ? (and daemonizing it again)

then later you want to do something like

    cmd>appname -stop

and this will quit it

Is that right ?

yes Norman, at the moment this is the right code:

#If Not DebugBuild Then 
    if args.ubound >= 1 then
	If (args(1) = "start" Or args(1) = "-d") Then // Check for command-line parameter to daemonize
		If Not App.Daemonize Then
			System.DebugLog("Could not daemonize the application")
			Return -1
		else
			System.DebugLog("Engine ON")
		end
	elseif args(1) = "restart" then
	// to do	
       end			
 else
	System.DebugLog("Not daemonized")
 end
#Endif

you need to talk with the running instance and those cmds wont do that
they will try to start a new one with those cmd line parameters

I’d actually use the built in system services for running & restarting daemons

something like this http://raspberrypi.stackexchange.com/questions/43390/how-to-write-an-init-script

Something you might be able to do is use an IPCSocket to see if there’s one running already. On launch, see if the socket can connect, if it can, send a message to quit, if not tell the socket to listen so the next copy of the software can connect.

You could send kill signal to the running process

Consider using systemd on Raspbian and most other Linux distributions. Understanding Systemd Units and Unit Files and How To Use Systemctl to Manage Systemd Services and Units may be helpful.

Yeah, probably the best way, i’ll give it a try.