[LCP] zombie process...

Paul Gearon gearon at ieee.org
Wed Nov 14 19:53:07 UTC 2007


I should point out that you shouldn't be using system calls to do
simple things like getting your pid.  That's what glibc is for.  It
wraps all those system calls up into standard POSIX functions that you
*should* be calling.  In this case, use getpid(2).  For details type:
  man getpid

As for your zombie problem, they're waiting to be reaped.  The parent
can choose to read the exit status at any time, so the OS *must* keep
this info until the parent has collected it.  This is called reaping.
It's a simple matter of calling one of the synchronous wait()
functions.  On Linux these are wait, waitpid and waitid.  See wait(2)
for the details:
  man 2 wait

Regards,
Paul

On Nov 14, 2007 9:30 AM, Sayang Oin <sayangoin at hotmail.com> wrote:
>
> Hello,
>
>  can someone help me?
>
>  I start a process via clone function but I don't know how to exit my child
> process without get a zombie...
>
>  thank you in addvance
>  Sayangoin
>
>
>
>  // source code.................
>
>  #include <signal.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include <sched.h>
> #include <unistd.h>
> #include <syscall.h>    // for syscall(SYS_getpid)
> #include <syslog.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <sys/stat.h>
>
> #include "logCtrl.h"
>  int transProcessId=0;
> char transStack[0x40000];
>  pid_t mypid;
>
> int transProcess(){
>
>   mypid = syscall(SYS_getpid);
>    printLog(logTRANS,"create transProc %i",mypid);
>    return 0;
> }
>  void startTransProcess(){
>
>   mypid = syscall(SYS_getpid);
>    printLog(logMODUL1,"create transProc %i",mypid);
>    if(transProcessId>0) transProcessId=0;  // transProcessId initialisieren
>    transProcessId=clone(transProcess,
> &transStack[sizeof(transStack)-10],CLONE_VM|CLONE_FILES|CLONE_FS , 0);
>    if(transProcessId>0){
>     printLog(logMODUL1,"transProc gestartet (PID: %d)",transProcessId);
>   }
>   else {
>     printLog(logMODUL1,"transProc nicht startet (PID: %d)",transProcessId);
>   }
> };
>
> void modul1()
> {
>   //printLog(logMODUL1,"Modul1");
>
>   if (!transProcessId) startTransProcess();
>
> }
>
>  int mainprog()
> {
>   printLog(logMAIN,"Programm start");
>    while(1) {
>
>     modul1();
>
>     usleep(10*1000);
>
>   }
>
>   return 0;
>  }
>
>
>  //
> -------------------------------------------------------------------------
> //
> // -------------------------------------------------------------------------
> //
> //
> //
> *******************************************************************************************
> //
> //
> //
> *******************************************************************************************
> //
> int main (int argc,char *argv[]){
>
>   initLogCtrl();
>    mainprog();
>   return 0;
>
> }
>
>
> ________________________________
> Schon gesehen? Tolle Bilder von Sarah Connor gibt es hier! Live Search
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List
>
>



More information about the linuxCprogramming mailing list