Fork processes.

Alexandre Oliva oliva at dcc.unicamp.br
Tue Feb 9 20:08:02 PST 1999


On Feb  8, 1999, wayne <infotechsys at pivot.net> wrote:

> 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 want to make sure I understand you.  If I have a Invoice system.
> Customer system, Inventory control system , and they all interact
> with one another, then I would drive them thru one main() method.

If they're all written in Java, you could start them in separate
Threads instead of firing off new processes.  If they're separate
programs, you can use Runtime.exec() to start them.  But in Java you
can't just fork() an (almost) identical copy of a process as in
C/Unix, and doing it in native code is very dangerous too, because
the work of other threads will be duplicated in the parent and the
child process, which is certainly not what you mean.

For short: if you mean fork() followed by exec(), you want
Runtime.exec().  If you mean running multiple Java applications
concurrently, threads may do the job.  Otherwise, you can't fork()
reliably.

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil



More information about the kaffe mailing list