remove pidfile only when parent process died

This commit is contained in:
Edward Emelianov 2021-10-28 16:40:42 +03:00
parent 01e5b454e2
commit 6aec61d4a4
2 changed files with 7 additions and 4 deletions

View File

@ -31,11 +31,14 @@
#include "processmotors.h"
glob_pars *GP; // non-static: to use in outhern functions
static pid_t childpid;
void signals(int signo){
//restore_tty();
if(childpid){ // unlink PID-file only from father
unlink(GP->pidfile);
LOGERR("Exit with status %d", signo);
}
exit(signo);
}
@ -81,7 +84,7 @@ int main(int argc, char **argv){
check4running(self, GP->pidfile);
FREE(self);
while(1){ // guard for dead processes
pid_t childpid = fork();
childpid = fork();
if(childpid){
LOGDBG("Create child with PID %d", childpid);
DBG("Created child with PID %d\n", childpid);

View File

@ -104,7 +104,7 @@ static void *server(void *asock){
}
int nfd = 1;
// max amount of opened fd (+1 for server socket)
#define MAX_FDS (3)
#define MAX_FDS (11)
struct pollfd poll_set[MAX_FDS];
memset(poll_set, 0, sizeof(poll_set));
poll_set[0].fd = sock;