Skip to content

Commit 122fbc6

Browse files
committed
document kill
1 parent b30cae4 commit 122fbc6

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

doc/specs/stdlib_system.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,45 @@ if (p%completed) then
273273
print *, "Standard Error: ", p%stderr
274274
endif
275275
```
276+
277+
## `kill` - Terminate a running process
278+
279+
### Status
280+
281+
Experimental
282+
283+
### Description
284+
285+
The `kill` interface is used to terminate a running external process. It attempts to stop the process and returns a boolean flag indicating whether the operation was successful.
286+
This interface is useful when a process needs to be forcefully stopped, for example, if it becomes unresponsive or if its execution is no longer required.
287+
288+
### Syntax
289+
290+
`call ` [[stdlib_subprocess(module):kill(subroutine)]] `(process, success)`
291+
292+
### Arguments
293+
294+
`process`: Shall be a `type(process_type)` object representing the external process to be terminated.
295+
This is an `intent(inout)` argument, and on return is updated with the terminated process state.
296+
297+
`success`: Shall be a `logical` variable. It is set to `.true.` if the process was successfully killed, or `.false.` otherwise.
298+
299+
### Example
300+
301+
```fortran
302+
! Example usage of kill
303+
type(process_type) :: p
304+
logical :: success
305+
306+
! Start a process asynchronously
307+
p = run("sleep 10", wait=.false.)
308+
309+
! Attempt to kill the process
310+
call kill(p, success)
311+
312+
if (success) then
313+
print *, "Process successfully killed."
314+
else
315+
print *, "Failed to kill the process."
316+
end if
317+
```

src/stdlib_system.F90

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,34 @@ module subroutine update_process_state(process)
228228
end subroutine update_process_state
229229
end interface update
230230

231-
232-
! Kill a process
233231
interface kill
232+
!! version: experimental
233+
!!
234+
!! Terminates a running process.
235+
!! ([Specification](../page/specs/stdlib_system.html#kill-terminate-a-running-process))
236+
!!
237+
!! ### Summary
238+
!! Provides a method to kill or terminate a running process.
239+
!! Returns a boolean flag indicating whether the termination was successful.
240+
!!
241+
!! ### Description
242+
!!
243+
!! This interface allows for the termination of an external process that is still running.
244+
!! If the process is successfully killed, the `success` output flag is set to `.true.`, otherwise `.false.`.
245+
!! This function is useful for controlling and managing processes that are no longer needed or for forcefully
246+
!! stopping an unresponsive process.
247+
!!
248+
!! @note This operation may be system-dependent and could fail if the underlying user does not have
249+
!! the necessary rights to kill a process.
250+
!!
234251
module subroutine process_kill(process, success)
252+
!> The process object to be terminated.
235253
type(process_type), intent(inout) :: process
236-
! Return a boolean flag for successful operation
254+
!> Boolean flag indicating whether the termination was successful.
237255
logical, intent(out) :: success
238256
end subroutine process_kill
239-
end interface kill
257+
end interface kill
258+
240259

241260
!! version: experimental
242261
!!

0 commit comments

Comments
 (0)