Index: src/OFProcess.h ================================================================== --- src/OFProcess.h +++ src/OFProcess.h @@ -1,13 +1,17 @@ +#include + #import "OFStream.h" /** * \brief A class for stream-like communication with a newly created process. */ @interface OFProcess: OFStream { + pid_t pid; int readPipe[2], writePipe[2]; + int status; BOOL atEndOfStream; } /** * \brief Creates a new OFProcess with the specified program, program name and Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -1,10 +1,12 @@ #include "config.h" #include #include +#include + #import "OFProcess.h" #import "OFString.h" #import "OFArray.h" #import "OFInitializationFailedException.h" @@ -30,11 +32,11 @@ @try { if (pipe(readPipe) != 0 || pipe(writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: isa]; - switch (fork()) { + switch ((pid = fork())) { case 0:; OFString **cArray = [arguments cArray]; size_t i, count = [arguments count]; char **argv = alloca((count + 2) * sizeof(char*)); @@ -108,14 +110,11 @@ requestedLength: length]; } - (void)dealloc { - if (readPipe[0] != -1) - close(readPipe[0]); - if (writePipe[1] != -1) - close(writePipe[1]); + [self close]; [super dealloc]; } /* @@ -129,9 +128,13 @@ if (readPipe[0] != -1) close(readPipe[0]); if (writePipe[1] != -1) close(writePipe[1]); + if (pid != -1) + waitpid(pid, &status, WNOHANG); + + pid = -1; readPipe[0] = -1; writePipe[1] = -1; } @end