Fork: Difference between revisions
Content deleted Content added
Scala added |
|||
Line 877: | Line 877: | ||
#handle DisplayBanner("Welcome!")</lang> |
#handle DisplayBanner("Welcome!")</lang> |
||
=={{header| |
=={{header|Scala}}== |
||
[[Category:Scala Implementations]]{{libheader|Scala}} |
|||
===A Linux version=== |
|||
<lang scala>import java.io.IOException |
|||
object Fork extends App { |
|||
⚫ | |||
val builder: ProcessBuilder = new ProcessBuilder() |
|||
val currentUser: String = builder.environment.get("USER") |
|||
val command: java.util.List[String] = java.util.Arrays.asList("ps", "-f", "-U", currentUser) |
|||
builder.command(command) |
|||
try { |
|||
val lines = scala.io.Source.fromInputStream(builder.start.getInputStream).getLines() |
|||
println(s"Output of running $command is:") |
|||
while (lines.hasNext) println(lines.next()) |
|||
} |
|||
catch { |
|||
case iox: IOException => iox.printStackTrace() |
|||
} |
|||
}</lang> |
|||
===A Windows version=== |
|||
<lang scala>import java.io.IOException |
|||
object Fork extends App { |
|||
<lang slate>p@(Process traits) forkAndDo: b |
|||
val command: java.util.List[String] = java.util.Arrays.asList("cmd.exe", "/C", "ECHO.| TIME") |
|||
val builder: ProcessBuilder = new ProcessBuilder(command) |
|||
try { |
|||
val lines = scala.io.Source.fromInputStream(builder.start.getInputStream).getLines() |
|||
println(s"Output of running $command is:") |
|||
while (lines.hasNext) println(lines.next()) |
|||
} |
|||
catch { |
|||
case iox: IOException => iox.printStackTrace() |
|||
} |
|||
}</lang> |
|||
=={{header|Slate}}== |
|||
⚫ | The following built-in method uses the cloneSystem primitive (which calls fork()) to fork code. The parent and the child both get a socket from a socketpair which they can use to communicate. The cloneSystem is currently unimplemented on windows (since there isn't a fork() system call).<lang slate>p@(Process traits) forkAndDo: b |
||
[| ret | |
[| ret | |
||
(ret := lobby cloneSystem) |
(ret := lobby cloneSystem) |