@@ -92,14 +92,7 @@ Returns an object of type `process_type` that contains information about the sta
9292### Example
9393
9494``` 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!}
10396```
10497
10598## ` 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
130123### Example
131124
132125``` 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!}
148127```
149128
150129## ` 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
177156### Example
178157
179158``` 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!}
195160```
196161
197162## ` elapsed ` - Return process lifetime in seconds
@@ -224,17 +189,7 @@ Otherwise, the total process duration from creation until completion is returned
224189### Example
225190
226191``` 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!}
238193```
239194
240195## ` wait ` - Wait until a running process is completed
@@ -270,15 +225,7 @@ If not provided, the subroutine will wait indefinitely until the process complet
270225### Example
271226
272227``` 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!}
282229```
283230
284231## ` 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
306253### Example
307254
308255``` 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!}
323257```
324258
325259## ` kill ` - Terminate a running process
@@ -347,21 +281,7 @@ This is an `intent(inout)` argument, and on return is updated with the terminate
347281### Example
348282
349283``` 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!}
365285```
366286
367287## ` 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
387307### Example
388308
389309``` 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!}
397311```
398312
399313## ` 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
419333### Example
420334
421335``` 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!}
427337```
0 commit comments