Skip to content

Commit 06c7136

Browse files
committed
add oop example
1 parent 7653cc4 commit 06c7136

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ ADD_EXAMPLE(process_1)
22
ADD_EXAMPLE(process_2)
33
ADD_EXAMPLE(process_3)
44
ADD_EXAMPLE(process_4)
5+
ADD_EXAMPLE(process_5)

example/system/example_process_5.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Process example 5: Object-oriented interface
2+
program example_process_5
3+
use stdlib_system, only: process_type, runasync, is_windows, sleep
4+
implicit none
5+
type(process_type) :: process
6+
7+
if (is_windows()) then
8+
process = runasync("ping -n 10 127.0.0.1")
9+
else
10+
process = runasync("ping -c 10 127.0.0.1")
11+
endif
12+
13+
! Verify the process is running
14+
do while (process%is_running())
15+
16+
! Wait a bit before killing the process
17+
call sleep(millisec=1500)
18+
19+
print *, "Process has been running for ",process%elapsed()," seconds..."
20+
21+
end do
22+
23+
print *, "Process ",process%id," completed in ",process%elapsed()," seconds."
24+
25+
end program example_process_5

0 commit comments

Comments
 (0)