On Tue, Nov 28, 2006 at 09:12:00PM +0800, d tbsky wrote:
> but somtimes that message is not the last. like this:
> tcpserver: end 5165 status 256
> tcpserver: status: 5/40
> 5165 > 220 xxxxxxxxxxxxxxxx
> 5165 > [EOF]
Process 5165 wrote to stdout, exited, and was reaped by tcpserver
before recordio received a time slice.
> anyway i can make it allways the last message?
You need to ensure that recordio exits before tcpserver's child
process exits. Below is a quick blahwait program I threw together as
proof of concept; it forks and runs the passed program, waits for it
to return, then waits for one more process to exit (hopefully,
recordio) before returning itself.
You can then replace ``recordio foo...'' with ``recordio blahwait
foo...''. (Patching recordio or writing your own replacement would
probably be more robust.)
#include <unistd.h>
#include <sys/wait.h>
int main(int argc,char *argv[])
{
pid_t pid;
int status;
switch (pid = fork()) {
case -1: return 111;
case 0: execvp(argv[1],argv + 1); return 111;
}
close(0);
close(1);
waitpid(pid,&status,0);
wait(0);
if (!WIFEXITED(status)) return 111;
return WEXITSTATUS(status);
}
|