File: example_process_4.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (35 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
! Process example 4: Kill a running process
program example_process_kill
    use stdlib_system, only: process_type, runasync, is_running, kill, elapsed, is_windows, sleep
    implicit none
    type(process_type) :: process
    logical :: running, success

    print *, "Starting a long-running process..."
    if (is_windows()) then
        process = runasync("ping -n 10 127.0.0.1")
    else
        process = runasync("ping -c 10 127.0.0.1")
    endif

    ! Verify the process is running
    running = is_running(process)
    print *, "Process running:", running

    ! Wait a bit before killing the process
    call sleep(millisec=250) 

    print *, "Killing the process..."
    call kill(process, success)

    if (success) then
        print *, "Process killed successfully."
    else
        print *, "Failed to kill the process."
    endif

    ! Verify the process is no longer running
    running = is_running(process)
    print *, "Process running after kill:", running

end program example_process_kill