Re: fork,clone,CLONE_VM prob.

Feuer (feuer@his.com)
Sun, 06 Sep 1998 20:17:28 -0400


 

Konstantin Muenning wrote:

> On Sat, 5 Sep 1998, Zack Weinberg wrote:
>
> >>If it's realy true that also the stack pointer is passed identical to the
> >>child process so they use really the same physical memory it is clear that
> >>one of the processes cannot run right. In that case I have to allocate a
> >>new selector for the PL3 Stack (hmm, maybe for the PL0 stack too?),
> >[...]
> >
> >You're working too hard.  All you have to do is change the user-space stack
> >pointer to point at (the top of) a block of memory allocated for the
> >purpose, and jump into a new function.  If that function returns, make an
>
> I have tried to use a new sp in my test program. It was like this:
>
> int stack[10000];
> :
> pid=clone(&stack[5000],CLONE_VM);
> :
>
> this way the new stack sould become a free memory region (at the middle of
> the vector). But no difference. The child did nothing I could see.
>
> >exit() syscall.  Obviously you do this only in the child.
> >
> >Or you can use glibc, which has a clone() wrapper that does all this for
> >you.
>
> What/where is glibc? Do you mean glib.h? There is no function called
> clone.
>
> Could you please modify my test program
> (http://cip.physik.uni-bonn.de/~muenning/forktest.c) that way that the
> child process does something and mail it to me? The way you describe it
> sounds easy but I cannot see how it should work.
>
> Another thing that I don't understand is why the child process becomes a
> zombie when it exits (before the parent process). How can p.ex the shell
> make child processes (call programs...) and when they exit they do not
> become zombies? Or cron? My system should be full of zombies :-) but it
> isn't.
>
> OK, maybe I should describe the thing I am want to do with the
> forking/cloning. There may be some other way to do it I don't know about.
>
> I want to write some kind of specialized server app to wich a lot of
> clients can connect (network). So far it is nothing special. But this
> connection have to manage the clients and a data flow between them
> (something like messages etc.). With clone and CLONE_VM I could make every
> connection an own process but all would access the same "data pool". This
> would work without CLONE_VM if there is a comparable way to make an
> interprocess communication with N(>2) processes at the same time. I do not
> know any. Another approach would be to make a chained list of objects for
> every connection and to make something like a cooperative multitasking...
> it would need a lot of "tricks" to make it fulfil all my needs an I don't
> like it.
>
> Some suggestions?
>
> Thx!
> Konstantin Münning              ,,,                   uzs446@uni-bonn.de

glibc is called /usr/lib/libc-...
it is just the gnu libc.
to avoid zombies, parent processes must wait() for their children.  This often
occurs in a signal handler for SIGCHLD (see man signal or man sigaction).
I suspect that you don't really need to use clone.  It is too low-level even for
my taste.  Try using POSIX threads.  They should probably give you what you
need.  They basically provide a standard interface (on linux using clone), and
are designed for programmers, not library writers.  Hope this helps.

A lot of good stuff is in _Advanced Programming in the Unix Environment_ by
Stevens, but it does not do threads.  For networks, check out _Unix Network
Programming_ by Stevens, or perhaps a book on CORBA (for OO, high-level stuff).

David Feuer
feuer@his.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html