Bellow is the sample "TestBinary" i am using
main()
{
...
system("dd if=/dev/urandom of=/config/largeTestFile.txt count=1024 bs=11111111")
...
}
I have a main program that looks like this
int forkRet = fork();
if (forkRet > 0)
{
//We are the parent process so save the experiments process
testerProcId = forkRet;
printf("Started configFill with process id: %d\n", testerProcId);
}
else if (forkRet == 0)
{
//Run the experiment binary
if (execv(testerBinary, args) < 0)
//if(execl("/bin/sh", "sh", "-c", testerBinary, "argForBinary", NULL) < 0)
{
printf("Could not execv tester configFill, error: %s\n", strerror(errno));
}
exit(1);
}
kill(testerProcId, SIGKILL);
To make things clear this setup ends up creating 3 process, First is the main program (A), (A) then creates the second process (B) which is the TestBinary, the TestBinary ends up creating another process (C) through the system("dd ...") cmd.
My problem is that when (A) attempts to kill (B) i need it to also kill (C) which currently it does not. I have also tried using execl with the -c option in order to get (C) to die when (B) dies but this also did not seem to start my TestBinary.
I am pretty sure what i want to do is possible but im not sure if the system() cmd makes it impossible.
Aucun commentaire:
Enregistrer un commentaire