@@ -92,14 +92,7 @@ Returns an object of type `process_type` that contains information about the sta
92
92
### Example
93
93
94
94
``` fortran
95
- ! Example usage with command line or list of arguments
96
- type(process_type) :: p(2)
97
-
98
- ! Run a simple command line asynchronously
99
- p(1) = runasync("echo 'Hello, world!'", want_stdout=.true.)
100
-
101
- ! Run a command using an argument list asynchronously
102
- p(2) = runasync(["/usr/bin/ls", "-l"], want_stdout=.true.)
95
+ {!example/system/example_process_1.f90!}
103
96
```
104
97
105
98
## ` is_running ` - Check if a process is still running
@@ -130,21 +123,7 @@ After a call to `is_running`, the `type(process_type)` structure is also updated
130
123
### Example
131
124
132
125
``` fortran
133
- ! Example usage of is_running
134
- type(process_type) :: proc
135
- logical :: status
136
-
137
- ! Start an asynchronous process
138
- proc = run("sleep 10", wait=.false.)
139
-
140
- ! Check if the process is running
141
- status = is_running(proc)
142
-
143
- if (status) then
144
- print *, "Process is still running."
145
- else
146
- print *, "Process has terminated."
147
- end if
126
+ {!example/system/example_process_2.f90!}
148
127
```
149
128
150
129
## ` is_completed ` - Check if a process has completed execution
@@ -177,21 +156,7 @@ After a call to `is_completed`, the `type(process_type)` structure is updated to
177
156
### Example
178
157
179
158
``` fortran
180
- ! Example usage of is_completed
181
- type(process_type) :: proc
182
- logical :: status
183
-
184
- ! Start an asynchronous process
185
- proc = run("sleep 5", wait=.false.)
186
-
187
- ! Check if the process has completed
188
- status = is_completed(proc)
189
-
190
- if (status) then
191
- print *, "Process has completed."
192
- else
193
- print *, "Process is still running."
194
- end if
159
+ {!example/system/example_process_1.f90!}
195
160
```
196
161
197
162
## ` elapsed ` - Return process lifetime in seconds
@@ -224,17 +189,7 @@ Otherwise, the total process duration from creation until completion is returned
224
189
### Example
225
190
226
191
``` fortran
227
- ! Example usage of elapsed
228
- type(process_type) :: p
229
- real(RTICKS) :: delta_t
230
-
231
- ! Create a process
232
- p = run("sleep 5", wait=.false.)
233
-
234
- ! Check elapsed time after 2 seconds
235
- call sleep(2)
236
- delta_t = elapsed(p)
237
- print *, "Elapsed time (s): ", delta_t
192
+ {!example/system/example_process_3.f90!}
238
193
```
239
194
240
195
## ` wait ` - Wait until a running process is completed
@@ -270,15 +225,7 @@ If not provided, the subroutine will wait indefinitely until the process complet
270
225
### Example
271
226
272
227
``` fortran
273
- ! Example usage of wait
274
- type(process_type) :: p
275
-
276
- ! Start an asynchronous process
277
- p = run("sleep 5", wait=.false.)
278
-
279
- ! Wait for process to complete with a 10-second timeout
280
- call wait(p, max_wait_time=10.0)
281
- print *, "Process completed or timed out."
228
+ {!example/system/example_process_2.f90!}
282
229
```
283
230
284
231
## ` update ` - Update the internal state of a process
@@ -306,20 +253,7 @@ This is an `intent(inout)` argument, and its internal state is updated on comple
306
253
### Example
307
254
308
255
``` fortran
309
- ! Example usage of update
310
- type(process_type) :: p
311
-
312
- ! Start an asynchronous process
313
- p = run("sleep 5", wait=.false., want_stdout=.true., want_stderr=.true.)
314
-
315
- ! Periodically update the process state
316
- call update(p)
317
-
318
- ! After completion, print the captured stdout and stderr
319
- if (p%completed) then
320
- print *, "Standard Output: ", p%stdout
321
- print *, "Standard Error: ", p%stderr
322
- endif
256
+ {!example/system/example_process_5.f90!}
323
257
```
324
258
325
259
## ` kill ` - Terminate a running process
@@ -347,21 +281,7 @@ This is an `intent(inout)` argument, and on return is updated with the terminate
347
281
### Example
348
282
349
283
``` fortran
350
- ! Example usage of kill
351
- type(process_type) :: p
352
- logical :: success
353
-
354
- ! Start a process asynchronously
355
- p = run("sleep 10", wait=.false.)
356
-
357
- ! Attempt to kill the process
358
- call kill(p, success)
359
-
360
- if (success) then
361
- print *, "Process successfully killed."
362
- else
363
- print *, "Failed to kill the process."
364
- end if
284
+ {!example/system/example_process_4.f90!}
365
285
```
366
286
367
287
## ` sleep ` - Pause execution for a specified time in milliseconds
@@ -387,13 +307,7 @@ It ensures that the requested sleep duration is honored on both Windows and Unix
387
307
### Example
388
308
389
309
``` fortran
390
- ! Example usage of sleep
391
- print *, "Starting sleep..."
392
-
393
- ! Sleep for 500 milliseconds
394
- call sleep(500)
395
-
396
- print *, "Finished sleeping!"
310
+ {!example/system/example_sleep.f90!}
397
311
```
398
312
399
313
## ` is_windows ` - Check if the system is running on Windows
@@ -419,9 +333,5 @@ Returns a `logical` flag: `.true.` if the system is Windows, or `.false.` otherw
419
333
### Example
420
334
421
335
``` fortran
422
- if (is_windows()) then
423
- print *, "Running on Windows!"
424
- else
425
- print *, "Not running on Windows."
426
- end if
336
+ {!example/system/example_process_1.f90!}
427
337
```
0 commit comments