execv and defunct process
Hello All,
I have made a small program to execute an external program using execv. First I make some sanity check's like if the file exist then I execute the program (by root) doing an setuid to the user that requested the action. The execv is done after forking the process so my master process can still run.
The problem that I see is that even after the program/script ends, the instance created doesn't die, it remains at my process list as an defunct process consuming memory and cpu.
Here is the code:
Code:
switch ((pid = fork()))
{
case -1:
/* Fork() has failed */
perror ("fork");
return 0;
break;
case 0:
/* This is processed by the child */
//execv ("/tmp/echo1.sh", my_args);
setuid(userid);
execv (prog, argument);
printf("Failed to run prog [%s] for userid [%s]\n",prog,userid);
exit(EXIT_FAILURE);
return 0;
break;
default:
/* This is processed by the parent */
return 0;
break;
}
The process list:
Code:
26617 ? S 0:00 executeit
26618 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26634 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26646 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26658 ? Z 0:00 \_ [run_trigger_bil <defunct>]
26659 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26682 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26694 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26706 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26718 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26730 ? Z 0:00 \_ [run_trigger_bil <defunct>]
26731 ? Z 0:00 \_ [executeit <defunct>]
26732 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26755 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26767 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26783 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26795 ? Z 0:00 \_ [run_read_to_pro <defunct>]
26810 ? Z 0:00 \_ [run_trigger_bil <defunct>]
31258 ? S 0:00 \_ /bin/sh /home/groo/run_read_to_profilo.sh
31268 ? S 0:00 | \_ /usr/bin/php /home/groo/read_to_profilo.php
31269 ? Z 0:00 \_ [run_trigger_bil <defunct>]
31270 ? Z 0:00 \_ [executeit <defunct>]
top:
Code:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
8308 groous 8 0 0 0 0 Z 0.5 0.0 0:00 run_read_to_pro <defunct>
8296 groous 8 0 0 0 0 Z 0.9 0.0 0:00 run_read_to_pro <defunct>
8284 groous 8 0 0 0 0 Z 0.5 0.0 0:00 run_read_to_pro <defunct>
8261 groous 8 0 0 0 0 Z 0.5 0.0 0:00 run_trigger_bil <defunct>
8262 groous 8 0 0 0 0 Z 0.3 0.0 0:00 run_read_to_pro <defunct>
8249 groous 8 0 0 0 0 Z 0.3 0.0 0:00 run_read_to_pro <defunct>
I'm using Linux Red Hat 8.0.
Any help ?
Thanks a lot,