diff -r 1c4f9355fba3 -r e3865533e6a6 Process.st --- a/Process.st Sun Jan 29 11:04:01 2017 +0000 +++ b/Process.st Wed Feb 01 11:28:48 2017 +0000 @@ -1,5 +1,3 @@ -"{ Encoding: utf8 }" - " COPYRIGHT (c) 1992 by Claus Gittinger All Rights Reserved @@ -20,7 +18,7 @@ restartable interruptActions exitActions suspendSemaphore singleStepping emergencySignalHandler suspendActions creatorId processGroupId interruptsDisabled priorityRange - exceptionHandlerSet processType environment' + exceptionHandlerSet processType environment startTimestamp' classVariableNames:'TerminateSignal RestartSignal CaughtSignals' poolDictionaries:'' category:'Kernel-Processes' @@ -723,6 +721,17 @@ ^ startBlock ! +startTimestamp + "return the processes' start time" + + startTimestamp notNil ifTrue:[ + ^ startTimestamp + ]. + "/ the very first system process has no starttime set + startTimestamp := Smalltalk imageStartTime. + ^ startTimestamp +! + state "return a symbol describing the processes state" @@ -1712,40 +1721,45 @@ |block| - (block := startBlock) notNil ifTrue:[ - "/ - "/ just for your convenience ... - "/ - name isNil ifTrue:[ - name := '(' , block displayString , ')' - ]. - restartable ~~ true ifTrue:[startBlock := nil]. - - [ - "/ - "/ handle Process-Termination, Process-Restart and Abort - "/ - CaughtSignals handle:[:ex | - ex creator == RestartProcessRequest ifTrue:[ - ex restart - ]. - ex return - ] do:[ - exceptionHandlerSet isNil ifTrue:[ - exceptionHandlerSet := ExceptionHandlerSet new. - ]. - "/ - "/ block is the one which received the fork some time ago... - "/ - exceptionHandlerSet handleDo:block - ] - ] ensure:[self terminateNoSignal]. - ] ifFalse:[ - "is this artificial restriction useful ?" - self error:'a process cannot be started twice' mayProceed:true - ] - - "Modified: / 17.11.2001 / 16:45:32 / cg" + startBlock isNil ifTrue:[ + "is this artificial restriction useful ?" + self error:'a process cannot be started twice' mayProceed:true. + ^ self. + ]. + + "/ + "/ just for your convenience ... + "/ + startTimestamp := Timestamp now. + name isNil ifTrue:[ + name := '(' , startBlock displayString , ')' + ]. + + "save block for possible restart" + block := startBlock. + restartable ~~ true ifTrue:[ + startBlock := nil + ]. + + [ + "/ + "/ block is the one which received the fork/newProcess some time ago... + "/ + self exceptionHandlerSet handleDo:block + ] on:CaughtSignals do:[:ex | + "/ + "/ CaughtSignals: handle Process-Termination, Process-Restart and Abort + "/ + ex creator == RestartProcessRequest ifTrue:[ + ex restart + ]. + ex return + ] ensure:[ + self terminateNoSignal + ]. + + "Modified: / 17-11-2001 / 16:45:32 / cg" + "Modified: / 31-01-2017 / 16:41:05 / stefan" ! ! !Process methodsFor:'suspend & resume'! @@ -1862,52 +1876,52 @@ |wasBlocked| - Processor activeProcess ~~ self ifTrue:[ - wasBlocked := OperatingSystem blockInterrupts. - [ - state == #osWait ifTrue:[ - self terminateNoSignal. - ^ self. - ]. - - "if the receiver had no chance to execute yet, - it can be shot down without a signal" - - self suspendedContext isNil ifTrue:[ - self terminateNoSignal. - ^ self - ] - ] ensure:[ - wasBlocked ifFalse:[OperatingSystem unblockInterrupts] - ]. - - "register an interrupt action and resume that process" - self interruptWith:[ - NoHandlerError handle:[:ex | - ex exception creator == TerminateProcessRequest ifTrue:[ - ex return. - ]. - ex reject. - ] do:[ - TerminateProcessRequest raise. - ]. - self terminateNoSignal. - ]. - ] ifFalse:[ - "terminating myself" - - NoHandlerError handle:[:ex | - ex exception creator == TerminateProcessRequest ifTrue:[ - ex return. - ]. - ex reject. - ] do:[ - TerminateProcessRequest raise. - ]. - self terminateNoSignal. - ] - - "Modified: / 24.8.1998 / 18:29:46 / cg" + Processor activeProcess == self ifTrue:[ + "suicide: terminating myself" + NoHandlerError handle:[:ex | + "unhandled TerminateProcessRequest is not an error" + ex exception creator ~~ TerminateProcessRequest ifTrue:[ + ex reject. + ]. + ] do:[ + TerminateProcessRequest raise. + ]. + self terminateNoSignal. + "not reached" + ^ self. + ]. + + "the receiver is terminated from another process" + wasBlocked := OperatingSystem blockInterrupts. + [ + (state isNil or:[state == #dead]) ifTrue:[ + ^ self. + ]. + state == #osWait ifTrue:[ + "osWait processes cannot be interrupted" + self terminateNoSignal. + ^ self. + ]. + + self suspendedContext isNil ifTrue:[ + "if the receiver had no chance to execute yet, + it can be shot down without a signal" + self terminateNoSignal. + ^ self + ] + ] ensure:[ + wasBlocked ifFalse:[OperatingSystem unblockInterrupts] + ]. + + "register an interrupt action, so that I am terminating myself" + self interruptWith:[ + self terminate. + ]. + "maybe I am stopped - resume so that I can die" + self resume. + + "Modified: / 24-08-1998 / 18:29:46 / cg" + "Modified (comment): / 27-01-2017 / 18:08:46 / stefan" ! terminateAllGUISubprocesses @@ -1929,17 +1943,14 @@ ^ self ]. ProcessorScheduler knownProcesses do:[:aProcess | - aProcess ~~ self ifTrue:[ - aProcess creatorId == id ifTrue:[ - aProcess isGUIProcess ifTrue:[ - aProcess terminateWithAllGUISubprocesses - ] - ] - ] + (aProcess ~~ self and:[aProcess creatorId == id and:[aProcess isGUIProcess]]) ifTrue:[ + aProcess terminateWithAllGUISubprocesses + ]. ]. "Created: / 28-10-1996 / 20:43:32 / cg" "Modified: / 26-10-2012 / 13:16:35 / cg" + "Modified: / 24-01-2017 / 17:38:10 / stefan" ! terminateAllSubprocessesInGroup @@ -1971,15 +1982,14 @@ and recursively oll of their group processes.)." ProcessorScheduler knownProcesses do:[:aProcess | - aProcess ~~ self ifTrue:[ - (aProcess processGroupId == aGroup) ifTrue:[ - aProcess terminateWithAllSubprocessesInGroup - ] - ] + (aProcess ~~ self and:[aProcess processGroupId == aGroup]) ifTrue:[ + aProcess terminateWithAllSubprocessesInGroup + ]. ]. - "Created: / 28.10.1996 / 20:43:32 / cg" - "Modified: / 3.11.1997 / 00:28:06 / cg" + "Created: / 28-10-1996 / 20:43:32 / cg" + "Modified: / 03-11-1997 / 00:28:06 / cg" + "Modified: / 24-01-2017 / 17:42:33 / stefan" ! terminateGroup @@ -2000,13 +2010,13 @@ ^ self ]. ProcessorScheduler knownProcesses do:[:aProcess | - aProcess ~~ self ifTrue:[ - aProcess processGroupId == id ifTrue:[ - aProcess terminate - ] - ] + (aProcess ~~ self and:[aProcess processGroupId == id]) ifTrue:[ + aProcess terminate + ]. ]. self terminate + + "Modified: / 24-01-2017 / 17:41:12 / stefan" ! terminateNoSignal @@ -2060,17 +2070,20 @@ ProcessorScheduler invalidProcessSignal raiseWith:self errorString:'trying to terminate the system process group'. ]. - ProcessorScheduler knownProcesses do:[:aProcess | - aProcess ~~ self ifTrue:[ - (aProcess processGroupId == processGroupId - or:[aProcess processGroupId == id]) ifTrue:[ - aProcess terminate - ] - ] + ProcessorScheduler knownProcesses do:[:eachProcess | + eachProcess ~~ self ifTrue:[ + |eachProcessGroupId| + + eachProcessGroupId := eachProcess processGroupId. + (eachProcessGroupId == processGroupId or:[eachProcessGroupId == id]) ifTrue:[ + eachProcess terminate + ]. + ]. ]. - "Created: 28.10.1996 / 20:41:49 / cg" - "Modified: 26.8.1997 / 03:09:57 / cg" + "Created: / 28-10-1996 / 20:41:49 / cg" + "Modified: / 26-08-1997 / 03:09:57 / cg" + "Modified: / 24-01-2017 / 17:35:25 / stefan" ! terminateWithAllGUISubprocesses