try setting the session id and killing the process group instead (man 2 kill)
int main(void) {
pid_t childProc = fork();
switch (childProc) {
case -1:
perror("fork() error");
exit(EXIT_FAILURE);
case 0:
setsid();
system("find / -print" );
printf("if I use kill(pid, SIGTERM) control doesnt reach here");
exit(EXIT_SUCCESS);
default:
sleep(1);
kill(childProc*-1, SIGTERM);
break;
}
printf("Exit!!!!!!");
return EXIT_SUCCESS;
}
this more or less works. The caveat is that there's a bit of a race in that the parent has to give the child time to setsid(), hence the sleep.
Hope that helps.