[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] signaler og SIGCHILD



Peter Makholm <sslug@sslug> writes:

> Du kan eventuelt lade din handler for SIGCHLD gøre noget ala følgende:
> 
> voin handle_sigchld(int signum) {
>     int* status;
>     pid_t pid;
> 
>     /* Collect all terminated childrens */
>     while(pid = waitpid(-1, status, WNOHANG) {}
> } 
> 
> Det er ikke efterprøvet, og der skal måske også lige lidt ekstra
> fejlhåndtering til.

Det er den mere portable løsning, men det er nok ikke en god ide at
overføre en pointer til et tilfældigt sted i hukommelsen til waitpid
som status argument:

int status;
pid_t pid;

while ((pid = waitpid(-1, &status, WNOHANG)) != -1) {
 ...
}

Ellers man kan også bare overføre NULL som status hvis man er ligeglad
med exit code.

Husk at man er yderst begrænset i hvad man kan gøre i sin signal
handler (ingen stdio, malloc etc.). Vil du opdatere nogle strukturer
eller lignende (fx linked liste af børn) skal du overveje fx noget med
at maskere SIGCHLD i de sektioner der håndterer det i hovedprogrammet. 
Eller fx skrive child-PID i en pipe som du læser fra.


-- 
===============================================================
<sslug@sslug>                           Herlev, Denmark     
<URL:http://www.andreasen.org/>                             <*>   
===============================================================



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *