This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

38
Task/Fork/Java/fork.java Normal file
View file

@ -0,0 +1,38 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class RFork {
public static void main(String[] args) {
ProcessBuilder pb;
Process pp;
List<String> command;
Map<String, String> env;
BufferedReader ir;
String currentuser;
String line;
try {
command = Arrays.asList("");
pb = new ProcessBuilder(command);
env = pb.environment();
currentuser = env.get("USER");
command = Arrays.asList("ps", "-f", "-U", currentuser);
pb.command(command);
pp = pb.start();
ir = new BufferedReader(new InputStreamReader(pp.getInputStream()));
line = "Output of running " + command.toString() + " is:";
do {
System.out.println(line);
} while ((line = ir.readLine()) != null);
}
catch (IOException iox) {
iox.printStackTrace();
}
return;
}
}

View file

@ -0,0 +1,27 @@
/* NetRexx */
options replace format comments java crossref symbols binary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
do
pb = ProcessBuilder([String ''])
env = pb.environment()
currentuser = String env.get('USER')
command = Arrays.asList([String 'ps', '-f', '-U', currentuser])
pb.command(command)
pp = pb.start()
ir = BufferedReader(InputStreamReader(pp.getInputStream()))
line = String 'Output of running' command.toString() 'is:'
loop label w_ until line = null
say line
line = ir.readLine()
end w_
catch iox = IOException
iox.printStackTrace()
end
return

View file

@ -0,0 +1,11 @@
import posix
var pid = fork()
if pid < 0:
# error forking a child
elif pid > 0:
# parent, and pid is process id of child
else:
# child
quit()
# further Parent stuff here