diff --git a/src/LibCompat/OSProcess.class.st b/src/LibCompat/OSProcess.class.st index 1cc4346..b6f623e 100644 --- a/src/LibCompat/OSProcess.class.st +++ b/src/LibCompat/OSProcess.class.st @@ -8,7 +8,9 @@ Class { #name : #OSProcess, #superclass : #Object, #instVars : [ - 'process' + 'command', + 'pid', + 'status' ], #category : #LibCompat } @@ -23,31 +25,41 @@ OSProcess class >> command: aString [ { #category : #accesing } OSProcess >> command: aString [ - process shellCommand: aString. + command := aString ] { #category : #initialization } OSProcess >> initialize [ - process := OSSUnixSubprocess new. + (Smalltalk globals includesKey: #OSSUnixSubprocess) ifTrue:[ + self error: 'OSSubProcess package loaded. OSSubProcess is incompatbile with LibCompat''s OSProcess implementation.' + ]. ] { #category : #testing } OSProcess >> isComplete [ - ^process isComplete + ^status notNil ] { #category : #testing } OSProcess >> isRunning [ - ^process isRunning + ^status isNil. ] { #category : #running } OSProcess >> startProcess [ - process run + pid := Smalltalk os spawn: {'/bin/sh' . '-c' . command} stdin: Stdio stdin stdout: Stdio stdout stderr: Stdio stderr exit: [ :sts | status := sts. ]. ] { #category : #'terminating child' } OSProcess >> terminate [ - process terminate + pid isNil ifTrue:[ + self error: 'Process not (yet) running'. + ^ self. + ]. + status notNil ifTrue:[ + self error: 'Process already terminated'. + ]. + LibC kill: pid _: 15"SIGTERM" + ] diff --git a/src/LibUnix/LibC.extension.st b/src/LibUnix/LibC.extension.st index 3273ee4..b8110df 100644 --- a/src/LibUnix/LibC.extension.st +++ b/src/LibUnix/LibC.extension.st @@ -77,6 +77,12 @@ LibC class >> ioctl: fd _: request _: param [ ^ self ffiCall:#( int ioctl(int fd, long request, void* param) ) module: LibC ] +{ #category : #'*LibUnix' } +LibC class >> kill: pid _: sig [ + ^ self ffiCall:#(int kill(int pid, int sig)) module: LibC + +] + { #category : #'*LibUnix' } LibC class >> open: pathname _: flags [ ^ self ffiCall: #(int open(char* pathname, int flags)) module: LibC diff --git a/src/LibUnix/UnixProcessStatus.class.st b/src/LibUnix/UnixProcessStatus.class.st index c387597..3fb7baf 100644 --- a/src/LibUnix/UnixProcessStatus.class.st +++ b/src/LibUnix/UnixProcessStatus.class.st @@ -37,6 +37,20 @@ UnixProcessStatus >> pid: pidValue wstatus: wstatusValue [ wstatus := wstatusValue ] +{ #category : #printing } +UnixProcessStatus >> printOn: aStream [ + super printOn: aStream. + aStream nextPutAll: '(pid '. + pid printOn: aStream. + aStream nextPutAll: ', '. + aStream nextPutAll: self status. + aStream nextPutAll: ' '. + self code printOn: aStream. + aStream nextPutAll: ')'. + + +] + { #category : #accessing } UnixProcessStatus >> status [ "return status as a Symbol;