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   |
 |
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
|
|
|
 |
|
Write an app to start and kill another app periodically
By: jpderyck on Thu, 29 April 2010 17:33
|
 |
|
Re: Write an app to start and kill another app periodically
By: koldo on Thu, 29 April 2010 17:51
|
 |
|
Re: Write an app to start and kill another app periodically
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Fri, 30 April 2010 10:32
|
 |
|
Re: Write an app to start and kill another app periodically
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Tue, 07 September 2010 15:16
|
 |
|
Re: Write an app to start and kill another app periodically
By: dolik.rce on Tue, 07 September 2010 15:55
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Tue, 07 September 2010 18:23
|
 |
|
Re: Write an app to start and kill another app periodically
By: dolik.rce on Tue, 07 September 2010 22:07
|
 |
|
Re: Write an app to start and kill another app periodically
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Wed, 08 September 2010 10:56
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Wed, 08 September 2010 10:36
|
 |
|
Re: Write an app to start and kill another app periodically
By: dolik.rce on Wed, 08 September 2010 11:25
|
 |
|
Re: Write an app to start and kill another app periodically
By: jpderyck on Wed, 08 September 2010 16:26
|
Goto Forum:
Current Time: Wed Aug 27 19:31:58 CEST 2025
Total time taken to generate the page: 0.05977 seconds
|