UnixOperatingSystem.st
changeset 20328 d27372774fc9
parent 20327 e70f8895a3cb
child 20345 68e5382ae472
child 20382 870f6e63c6aa
--- a/UnixOperatingSystem.st	Thu Sep 01 18:58:06 2016 +0200
+++ b/UnixOperatingSystem.st	Thu Sep 01 19:00:03 2016 +0200
@@ -3534,6 +3534,81 @@
     errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
     environment:anEvironmentDictionary inDirectory:dir
 
+    ^ self
+        startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
+        errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
+        environment:anEvironmentDictionary inDirectory:dir showWindow:nil
+
+    "blocking at current prio (i.e. only higher prio threads execute):
+
+     OperatingSystem executeCommand:'ls -l > out'.
+     OperatingSystem executeCommand:#('/bin/ls' '-l') outputTo:Transcript.
+    "
+
+    "non-blocking (lower prio threads continue):
+
+     |in out err pid sema|
+
+     in := 'out' asFilename readStream.
+     out := 'out2' asFilename writeStream.
+     err := 'err' asFilename writeStream.
+
+     sema := Semaphore new.
+     pid := OperatingSystem startProcess:'sleep 10; grep drw' inputFrom:in outputTo:out errorTo:err.
+
+     The following will no longer work. monitorPid has disappeared
+
+     pid notNil ifTrue:[
+         Processor monitorPid:pid action:[:osStatus | sema signal ].
+     ].
+     in close.
+     out close.
+     err close.
+     sema wait.
+     Transcript showCR:'finished'
+    "
+
+    "
+     |pid sema|
+
+     sema := Semaphore new.
+
+     Processor
+            monitor:[
+                pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err'
+            ]
+            action:[:osStatus | sema signal ].
+
+     sema wait.
+     Transcript showCR:'finished'
+    "
+
+    "
+     |pid sema|
+
+     sema := Semaphore new.
+
+     Processor
+            monitor:[
+                pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err'
+            ]
+            action:[:osStatus | sema signal ].
+
+     Delay waitForSeconds:2.
+     OperatingSystem terminateProcess:pid.
+     Transcript showCR:'terminated'
+    "
+
+    "Modified: / 21.3.1997 / 10:04:35 / dq"
+    "Modified: / 15.7.1997 / 16:03:51 / stefan"
+    "Modified: / 5.6.1998 / 19:03:51 / cg"
+    "Created: / 12.11.1998 / 14:39:20 / cg"
+!
+
+startProcess:aCommandString inputFrom:anExternalInStream outputTo:anExternalOutStream
+    errorTo:anExternalErrStream auxFrom:anAuxiliaryStream
+    environment:anEvironmentDictionary inDirectory:dir showWindow:ignoredHere
+
     "start executing the OS command as specified by the argument, aCommandString
      as a separate process; do not wait for the command to finish.
      If aCommandString is a String, the commandString is passed to a shell for execution
@@ -3551,36 +3626,36 @@
     aCommandString isNil ifTrue:[^ nil].
 
     (in := anExternalInStream) isNil ifTrue:[
-	nullStream := Filename nullDevice readWriteStream.
-	in := nullStream.
+        nullStream := Filename nullDevice readWriteStream.
+        in := nullStream.
     ].
     (out := anExternalOutStream) isNil ifTrue:[
-	nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
-	out := nullStream.
+        nullStream isNil ifTrue:[nullStream := Filename nullDevice writeStream].
+        out := nullStream.
     ].
     (err := anExternalErrStream) isNil ifTrue:[
-	err := out
+        err := out
     ].
     anAuxiliaryStream notNil ifTrue:[
-	auxFd := anAuxiliaryStream fileDescriptor
+        auxFd := anAuxiliaryStream fileDescriptor
     ].
 
     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
 
     rslt := self
-	exec:(shellAndArgs at:1)
-	withArguments:(shellAndArgs at:2)
-	environment:anEvironmentDictionary
-	fileDescriptors:(Array with:in fileDescriptor
-			       with:out fileDescriptor
-			       with:err fileDescriptor
-			       with:auxFd)
-	fork:true
-	newPgrp:true "/ false
-	inDirectory:dir.
+        exec:(shellAndArgs at:1)
+        withArguments:(shellAndArgs at:2)
+        environment:anEvironmentDictionary
+        fileDescriptors:(Array with:in fileDescriptor
+                               with:out fileDescriptor
+                               with:err fileDescriptor
+                               with:auxFd)
+        fork:true
+        newPgrp:true "/ false
+        inDirectory:dir.
 
     nullStream notNil ifTrue:[
-	nullStream close.
+        nullStream close.
     ].
 
     ^ rslt
@@ -3605,7 +3680,7 @@
      The following will no longer work. monitorPid has disappeared
 
      pid notNil ifTrue:[
-	 Processor monitorPid:pid action:[:osStatus | sema signal ].
+         Processor monitorPid:pid action:[:osStatus | sema signal ].
      ].
      in close.
      out close.
@@ -3620,10 +3695,10 @@
      sema := Semaphore new.
 
      Processor
-	    monitor:[
-		pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err'
-	    ]
-	    action:[:osStatus | sema signal ].
+            monitor:[
+                pid := OperatingSystem startProcess:'(sleep 2; ls -l) > out 2>err'
+            ]
+            action:[:osStatus | sema signal ].
 
      sema wait.
      Transcript showCR:'finished'
@@ -3635,10 +3710,10 @@
      sema := Semaphore new.
 
      Processor
-	    monitor:[
-		pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err'
-	    ]
-	    action:[:osStatus | sema signal ].
+            monitor:[
+                pid := OperatingSystem startProcess:'(sleep 1; echo 1; sleep 9; ls -l) > out 2>err'
+            ]
+            action:[:osStatus | sema signal ].
 
      Delay waitForSeconds:2.
      OperatingSystem terminateProcess:pid.