The following scenario:
process_1.bin
startsdoSomeThing.sh
doSomeThing.sh
should killprocess_1.bin
first but keep running itself and do some other things
I have tried fork, exec, screen, p_threads, daemon, and some without success.
Every time the doSomeThing.sh
starts and kills the process_1.bin
, it kills itself because the parent process is killed.
doSomeThing.sh
tells me: "leaving program after kill signal!"
Unfortunately, this does not work either:
pid_t pid;
pid = fork();
if (pid < 0)
exit(EXIT_FAILURE);
if (pid > 0) // Success: Let the parent terminate
exit(EXIT_SUCCESS);
if (setsid() < 0)
exit(EXIT_FAILURE);
pid = fork();
if (pid < 0)
exit(EXIT_FAILURE);
if (pid > 0)
exit(EXIT_SUCCESS);
// umask(0);
// chdir("/");
switch(pid)
{
case -1: // Fork() has failed
perror ("fork");
break;
case 0: // This is processed by the child
// deamon(0,0);
system("/root/doSomeThing.sh");
// system("screen -dmS doSomeThing /root/doSomething.sh")
// char *name[] = {
// "/bin/bash",
// "-c",
// "/root/doSomeThing.sh",
// NULL
// };
// if(execvp(name[0], name) < 0)
// perror("execvp");
exit(0);
break;
default: // This is processed by the parrent
break;
}
How can I direct the doSomeThing.sh
to kill the process_1.bin
but still stay alive itself?