Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - C-Like Fork?

Tags:

java

c

fork

Is it possible to do a "C like" fork in java, using an new independent jvm process ?

How?

like image 399
sakana Avatar asked Nov 13 '08 17:11

sakana


People also ask

Why fork() system call is used?

Fork system call is used for creating a new process, which is called child process, which runs concurrently with the process that makes the fork() call (parent process). After a new child process is created, both processes will execute the next instruction following the fork() system call.

Can you fork Java?

In Java, the fork/join framework provides support for parallel programming by splitting up a task into smaller tasks to process them using the available CPU cores. In fact, Java 8's parallel streams and the method Arrays#parallelSort use under the hood the fork/join framework to execute parallel tasks.

How does fork() work?

In the computing field, fork() is the primary method of process creation on Unix-like operating systems. This function creates a new copy called the child out of the original process, that is called the parent. When the parent process closes or crashes for some reason, it also kills the child process.

What is forked process in Java?

Fork is a process in which a task splits itself into smaller and independent sub-tasks which can be executed concurrently.


2 Answers

This answer is probably a little late but:

http://akuma.kohsuke.org/

seems to be exactly what your looking for

like image 110
user525362 Avatar answered Sep 23 '22 21:09

user525362


Funnily, I am just working on this: a Java process running other Java processes. I used the article From Runtime.exec() to ProcessBuilder as a solid base, and When Runtime.exec() won't as a good advice how to gobble the output streams.

PS.: For those wondering, I had to do that (instead of spawning new threads) because yet another Java process is checking the presence of these processes which are, normally, ran separately with shell commands.

like image 27
PhiLho Avatar answered Sep 19 '22 21:09

PhiLho