Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Write an app to start and kill another app periodically
Re: Write an app to start and kill another app periodically [message #26389 is a reply to message #26388] Thu, 29 April 2010 17:51 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3443
Registered: August 2008
Senior Veteran
jpderyck wrote on Thu, 29 April 2010 17:33

Hello,
Under Linux, I would like to write a small application which can check for a hung application periodically. If it is hung, it should kill the process and restart the application.

The application to be checked periodically was written in u++: it reads a data module acquisition connected by usb every 10 seconds. It runs for +/- 2 months and then it crash. I suppose the problem is with the usb driver or the usb module itself. I made the same program reading a different module connected by rs232 port with no problem.

I know that I have to use command like 'killall app'
How to start this kind of command from an u++ gui program ?

The best should be if the small checking app was a linux service. I saw a service app sample for windows, but does anybody have sample for linux ?

best regards
Jean-Paul


Hello jpderyck

I am not an expert but this works.

You can use function int kill(pid_t pid, int sig);

pid is the id of the process to be killed.

There are these options from less to more aggresive:

#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
...
	pid_t pid;
...
	kill(pid, SIGTSTP);
	kill(pid, SIGTERM);
	kill(pid, SIGHUP);
	kill(pid, SIGKILL);


You can put sleep() between kill() functions just to give the program a little opportunity to stop itself.

To get the pid you can use getpid() and put this value somewhere where the killer process can take it.





Best regards
IƱaki
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [BUG&FIX] LocalProcess can not be reused
Next Topic: String.Mid() and Unicode
Goto Forum:
  


Current Time: Wed Aug 27 19:31:58 CEST 2025

Total time taken to generate the page: 0.05977 seconds