Re: sys_fork

Ricardo Nabinger Sanchez <[email protected]>
Newsgroups org.kernel.vger.linux-assembly
Message-ID <[email protected]>
Quoting  HIToC <[email protected]>
Sent on  Tue, 29 Nov 2005 19:59:56 +0100

Hello,

> Yes, the problem was that I do not considered the value in EAX!
> A possible solution to free system resources used by chlid, is to call
> sys_waitpid with argument pid setted to 0 and waiting until the
> value returned in EAX is greater than 0...
> Now I understand some more thing over the fork system call!!

that's nice, have you studied man 2 fork already? :)

I wouldn't recommend you to call wait4pid, because your process (the accept
() one) will block, and thus fork() will not be an advantage (you can do
that naturally without forking).

What would be a nice thing to do is to prepare a signal handler for
SIG_CHILD, to clean up its children.  It is very single to use, all you
need is to tell the kernel to use your custom function for handling
SIG_CHILD, instead of the default action (which is to ignore the signal,
and you'll end with a bunch of zombies).

Btw, such a function is like this in C:

void handle_sigchild() {
	wait();
}

notice that the process will not block, as the signal is being delivered
because of a terminating child.  it will be cleaned even if the process is
blocked in accept().

I'm almost sure that you'll also need to handle interrupted accept(), which
will return -1 and errno will have EINTR (interrupted system call).  in
this case, call accept() again :)

have fun :)

-- 
Ricardo Nabinger Sanchez
GNU/Linux #140696 [http://counter.li.org]
Slackware Linux + FreeBSD

  Left to themselves, things tend to go from bad to worse.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.