Fork processes.

Alex Nicolaou anicolao at mud.cgl.uwaterloo.ca
Tue Feb 9 13:48:40 PST 1999


Alexandre Oliva wrote:
> 
> On Feb  8, 1999, wayne <infotechsys at pivot.net> wrote:
> 
> > how to do a fork in a java program ? Can this be done?
> 
> Nope

I'm not sure if "Nope" is really the right answer. Do you really want to
fork() or do you want the equivalent of fork() in Java code (i.e.
duplicate a thread heirarchy?). Or do you really want exec()
functionality to run a *different* program from your java program?

Normally, the traditional Java way to get fork-like functionality would
just be to start a new thread. fork() is a pretty terrible kludge
anyway, linked into the guts of how UNIX systems create processes. But
if you truly want/need the identical functionality in Java code it may
be hard to come by (not to mention hard on the poor machine with fork'ed
VMs). 

You can use methods in the java.lang.Runtime class to spawn other
programs (including new copies of yourself that have a new memory
space). 

alex


More information about the kaffe mailing list