:: Re: [DNG] Doing away with multi-thr…
Top Pagina
Delete this message
Reply to this message
Auteur: Rainer Weikusat
Datum:  
Aan: dng
Onderwerp: Re: [DNG] Doing away with multi-threading in my project (netman)
Edward Bartolo <edbarx@???> writes:
> I am trying to reap zombies. The "while(fpwaitpid" pascal code is
> freezing my application.
>
> *********************************************************************************
> procedure handle_sigchld(sig: longint; info: psiginfo; context:
> psigcontext); cdecl;
> var
> Status: cint;
> a_pid: pid_t;
> begin
> Status := 0;
> a_pid := -1;
>
> // This is freezing my application
>   while (fpwaitpid(a_pid, Status, WNOHANG) > 0) do
>   begin
>     backend_lives := backend_lives + 1;
>     showmessage('hi strunz!!!');
>   end;
> end;

>
>
> var sa: sigactionrec;
>
> initialization
> sa.sa_handler := @handle_sigchld;
> fpsigemptyset(&sa.sa_mask);
>
>   sa.sa_flags := (SA_RESTART or SA_NOCLDSTOP);
>   if (fpsigaction(SIGCHLD, @sa, nil) = -1) then
>   begin
>     // do nothing
>   end;
> ******************************************************

>
> Any ideas?


As was already mentioned: The second argument to fpwaitpid must be a
pointer. As opposed to what was already mentioned, the loop condition is
generally correct: The loop must terminate if the return value is either
-1 (some kind of error occurred) or 0 (nothing more to do right now).

Caveat: The signal handler is asynchronously invoked by the kernel when
a SIGCHLD is posted and it will interrupt whatever else the application
was doing at the moment. This means it's as if it was running in a
separate thread (except even more complicated).

According to

http://www.freepascal.org/docs-html/rtl/baseunix/fpsigaction.html

    Sa_Handler may be SIG_DFL for the default action or SIG_IGN to
    ignore the signal.


For as long as you aren't using the exit status, using SIG_IGN instead
of a signal handler is to be preferred as the kernel will then just not
create zombies.