12890
|
1 |
"{ Package: 'stx:libbasic' }"
|
|
2 |
|
19286
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
12890
|
5 |
Object subclass:#OSProcess
|
21172
|
6 |
instanceVariableNames:'pid parentPid command environment directory inStream outStream
|
|
7 |
errorStream exitStatus finishSema'
|
12890
|
8 |
classVariableNames:''
|
|
9 |
poolDictionaries:''
|
|
10 |
category:'System-Support'
|
|
11 |
!
|
|
12 |
|
|
13 |
!OSProcess class methodsFor:'documentation'!
|
|
14 |
|
|
15 |
documentation
|
|
16 |
"
|
|
17 |
OSProcess is an abstract class. Instances represent operating system processes
|
|
18 |
(as opposed to Smalltalk processes).
|
|
19 |
|
|
20 |
[author:]
|
|
21 |
Stefan Vogel (stefan@zwerg)
|
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
pid SmallInteger the process id
|
|
25 |
parentPid SmallInteger the process id of the parent process
|
|
26 |
commandLine String the command line of the running command.
|
|
27 |
|
|
28 |
[class variables:]
|
|
29 |
|
|
30 |
[see also:]
|
|
31 |
Process
|
|
32 |
|
|
33 |
"
|
|
34 |
! !
|
|
35 |
|
21172
|
36 |
!OSProcess class methodsFor:'initialize'!
|
|
37 |
|
|
38 |
initialize
|
|
39 |
"Backward compatibility"
|
|
40 |
Win32Process := self.
|
|
41 |
! !
|
|
42 |
|
12890
|
43 |
!OSProcess methodsFor:'accessing'!
|
|
44 |
|
19298
|
45 |
accessor
|
|
46 |
^ self
|
|
47 |
!
|
|
48 |
|
21172
|
49 |
command
|
|
50 |
"return the value of the instance variable 'command' (automatically generated)"
|
|
51 |
|
|
52 |
^ command
|
|
53 |
|
|
54 |
"Created: / 10.11.1998 / 21:27:07 / cg"
|
|
55 |
!
|
|
56 |
|
|
57 |
command:something
|
|
58 |
"set the value of the instance variable 'command' (automatically generated)"
|
|
59 |
|
|
60 |
command := something.
|
|
61 |
|
|
62 |
"Created: / 10.11.1998 / 21:27:07 / cg"
|
|
63 |
!
|
|
64 |
|
|
65 |
directory
|
|
66 |
"return the value of the instance variable 'directory' (automatically generated)"
|
|
67 |
|
|
68 |
^ directory
|
|
69 |
|
|
70 |
"Created: / 10.11.1998 / 21:21:52 / cg"
|
|
71 |
!
|
|
72 |
|
|
73 |
directory:something
|
|
74 |
"set the value of the instance variable 'directory' (automatically generated)"
|
|
75 |
|
|
76 |
directory := something.
|
|
77 |
|
|
78 |
"Created: / 10.11.1998 / 21:21:52 / cg"
|
|
79 |
!
|
|
80 |
|
|
81 |
environment
|
|
82 |
"return the value of the instance variable 'environment' (automatically generated)"
|
|
83 |
|
|
84 |
^ environment
|
|
85 |
|
|
86 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
|
87 |
!
|
|
88 |
|
|
89 |
environment:something
|
|
90 |
"set the value of the instance variable 'environment' (automatically generated)"
|
|
91 |
|
|
92 |
environment := something.
|
|
93 |
|
|
94 |
"Created: / 10.11.1998 / 21:27:07 / cg"
|
|
95 |
!
|
|
96 |
|
|
97 |
errorStream
|
|
98 |
"return the value of the instance variable 'errorStream' (automatically generated)"
|
|
99 |
|
|
100 |
^ errorStream
|
|
101 |
|
|
102 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
12890
|
103 |
!
|
|
104 |
|
21172
|
105 |
errorStream:something
|
|
106 |
"set the value of the instance variable 'errorStream' (automatically generated)"
|
|
107 |
|
|
108 |
errorStream := something.
|
|
109 |
|
|
110 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
|
111 |
!
|
|
112 |
|
|
113 |
exitStatus
|
|
114 |
"return the value of the instance variable 'exitStatus' (automatically generated)"
|
|
115 |
|
|
116 |
^ exitStatus
|
|
117 |
|
|
118 |
"Created: / 10.11.1998 / 21:24:55 / cg"
|
|
119 |
!
|
|
120 |
|
|
121 |
exitStatus:something
|
|
122 |
"set the value of the instance variable 'exitStatus' (automatically generated)"
|
|
123 |
|
|
124 |
exitStatus := something.
|
|
125 |
|
|
126 |
"Created: / 10.11.1998 / 21:24:55 / cg"
|
|
127 |
!
|
|
128 |
|
|
129 |
finishSema
|
|
130 |
"return the value of the instance variable 'finishSema' (automatically generated)"
|
|
131 |
|
|
132 |
^ finishSema
|
|
133 |
|
|
134 |
"Created: / 10.11.1998 / 21:21:53 / cg"
|
|
135 |
!
|
|
136 |
|
|
137 |
finishSema:something
|
|
138 |
"set the value of the instance variable 'finishSema' (automatically generated)"
|
|
139 |
|
|
140 |
finishSema := something.
|
|
141 |
|
|
142 |
"Created: / 10.11.1998 / 21:21:53 / cg"
|
|
143 |
!
|
|
144 |
|
|
145 |
inStream
|
|
146 |
"return the value of the instance variable 'inStream' (automatically generated)"
|
|
147 |
|
|
148 |
^ inStream
|
|
149 |
|
|
150 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
|
151 |
!
|
|
152 |
|
|
153 |
inStream:something
|
|
154 |
"set the value of the instance variable 'inStream' (automatically generated)"
|
|
155 |
|
|
156 |
inStream := something.
|
|
157 |
|
|
158 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
|
159 |
!
|
|
160 |
|
|
161 |
outStream
|
|
162 |
"return the value of the instance variable 'outStream' (automatically generated)"
|
|
163 |
|
|
164 |
^ outStream
|
|
165 |
|
|
166 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
|
167 |
!
|
|
168 |
|
|
169 |
outStream:something
|
|
170 |
"set the value of the instance variable 'outStream' (automatically generated)"
|
|
171 |
|
|
172 |
outStream := something.
|
|
173 |
|
|
174 |
"Created: / 10.11.1998 / 21:26:34 / cg"
|
12890
|
175 |
!
|
|
176 |
|
|
177 |
parentPid
|
|
178 |
^ parentPid
|
|
179 |
!
|
|
180 |
|
|
181 |
parentPid:something
|
|
182 |
parentPid := something.
|
|
183 |
!
|
|
184 |
|
|
185 |
pid
|
|
186 |
^ pid
|
|
187 |
!
|
|
188 |
|
|
189 |
pid:something
|
|
190 |
pid := something.
|
|
191 |
! !
|
|
192 |
|
19298
|
193 |
!OSProcess methodsFor:'file queries'!
|
|
194 |
|
|
195 |
isExecutable:aPathName
|
|
196 |
^ aPathName asFilename isExecutable
|
|
197 |
! !
|
19286
|
198 |
|
13313
|
199 |
!OSProcess methodsFor:'printing'!
|
|
200 |
|
|
201 |
printOn:aStream
|
|
202 |
aStream
|
|
203 |
nextPutAll:self className;
|
|
204 |
nextPut:$(.
|
|
205 |
pid printOn:aStream.
|
|
206 |
aStream space.
|
21172
|
207 |
command printOn:aStream.
|
13313
|
208 |
aStream nextPut:$)
|
|
209 |
! !
|
|
210 |
|
12890
|
211 |
!OSProcess methodsFor:'queries'!
|
|
212 |
|
|
213 |
getProcessHandle
|
|
214 |
"some OperatingSystems redefine this to resolve this to a processHandle
|
|
215 |
(which must be explicitely freed later).
|
|
216 |
Others simply return the pid here"
|
|
217 |
|
|
218 |
^ self subclassResponsibility
|
|
219 |
!
|
|
220 |
|
|
221 |
isAlive
|
|
222 |
"answer true, if the process is still alive"
|
|
223 |
|
|
224 |
^ self subclassResponsibility
|
|
225 |
!
|
|
226 |
|
|
227 |
isDead
|
|
228 |
"answer true, if the process is no longer alive"
|
|
229 |
|
|
230 |
^ self isAlive not
|
|
231 |
! !
|
|
232 |
|
21172
|
233 |
!OSProcess methodsFor:'starting'!
|
|
234 |
|
|
235 |
startProcess
|
|
236 |
finishSema := Semaphore new.
|
|
237 |
|
|
238 |
Processor
|
|
239 |
monitor:[
|
|
240 |
pid := OperatingSystem
|
|
241 |
startProcess:command
|
|
242 |
inputFrom:inStream
|
|
243 |
outputTo:outStream
|
|
244 |
errorTo:errorStream
|
|
245 |
auxFrom:nil
|
|
246 |
environment:nil
|
|
247 |
inDirectory:directory
|
|
248 |
showWindow:false.
|
|
249 |
]
|
|
250 |
action:[:status |
|
|
251 |
status stillAlive ifFalse:[
|
|
252 |
exitStatus := status.
|
|
253 |
"/ paranoia?
|
|
254 |
pid notNil ifTrue:[
|
|
255 |
OperatingSystem terminateProcessGroup:pid.
|
|
256 |
OperatingSystem terminateProcess:pid.
|
|
257 |
OperatingSystem closePid:pid.
|
|
258 |
].
|
|
259 |
finishSema signal
|
|
260 |
].
|
|
261 |
].
|
|
262 |
|
|
263 |
pid isNil ifTrue:[
|
|
264 |
exitStatus := OperatingSystem osProcessStatusClass processCreationFailure.
|
|
265 |
^ false
|
|
266 |
].
|
|
267 |
|
|
268 |
^ true.
|
|
269 |
|
|
270 |
"Created: / 10.11.1998 / 21:23:50 / cg"
|
|
271 |
"Modified: / 10.11.1998 / 21:33:16 / cg"
|
|
272 |
! !
|
|
273 |
|
12890
|
274 |
!OSProcess methodsFor:'terminating'!
|
|
275 |
|
|
276 |
kill
|
|
277 |
"kill the process - the process does not get the chance to clean up"
|
|
278 |
|
|
279 |
^ self subclassResponsibility.
|
|
280 |
!
|
|
281 |
|
|
282 |
killGroup
|
20379
|
283 |
"kill the processGroup - the processes do not get the chance to clean up"
|
|
284 |
|
12890
|
285 |
^ self subclassResponsibility.
|
|
286 |
!
|
|
287 |
|
|
288 |
killWithAllChildren
|
|
289 |
"terminate gracefully the process with all of its child processes"
|
|
290 |
|
|
291 |
^ self subclassResponsibility.
|
|
292 |
!
|
|
293 |
|
|
294 |
terminate
|
|
295 |
"terminate the process gracefully"
|
|
296 |
|
|
297 |
^ self subclassResponsibility.
|
|
298 |
!
|
|
299 |
|
|
300 |
terminateGroup
|
|
301 |
"terminate the process group.
|
|
302 |
Under Windows, these is the same as terminateWithhAllChildren,
|
|
303 |
under unix, this terminates a subset of all children"
|
|
304 |
|
|
305 |
^ self subclassResponsibility.
|
|
306 |
!
|
|
307 |
|
|
308 |
terminateWithAllChildren
|
|
309 |
"terminate gracefully the process with all of its child processes"
|
|
310 |
|
|
311 |
^ self subclassResponsibility.
|
|
312 |
! !
|
|
313 |
|
|
314 |
!OSProcess class methodsFor:'documentation'!
|
|
315 |
|
19298
|
316 |
version
|
|
317 |
^ '$Header$'
|
|
318 |
!
|
|
319 |
|
12890
|
320 |
version_CVS
|
19286
|
321 |
^ '$Header$'
|
12890
|
322 |
! !
|
19286
|
323 |
|
21172
|
324 |
|
|
325 |
OSProcess initialize!
|