diff --git a/vlib/os/process.c.v b/vlib/os/process.c.v index cf887d65c5322f..51321853b38572 100644 --- a/vlib/os/process.c.v +++ b/vlib/os/process.c.v @@ -14,7 +14,14 @@ pub fn (mut p Process) signal_kill() { } p._signal_kill() p.status = .aborted - return +} + +// signal_term - terminate the process +pub fn (mut p Process) signal_term() { + if p.status !in [.running, .stopped] { + return + } + p._signal_term() } // signal_pgkill - kills the whole process group @@ -23,7 +30,6 @@ pub fn (mut p Process) signal_pgkill() { return } p._signal_pgkill() - return } // signal_stop - stops the process, you can resume it with p.signal_continue() @@ -33,7 +39,6 @@ pub fn (mut p Process) signal_stop() { } p._signal_stop() p.status = .stopped - return } // signal_continue - tell a stopped process to continue/resume its work @@ -43,7 +48,6 @@ pub fn (mut p Process) signal_continue() { } p._signal_continue() p.status = .running - return } // wait - wait for a process to finish. @@ -60,7 +64,6 @@ pub fn (mut p Process) wait() { return } p._wait() - return } // close - free the OS resources associated with the process. @@ -132,7 +135,6 @@ pub fn (mut p Process) set_redirect_stdio() { $if trace_process_pipes ? { eprintln('${@LOCATION}, pid: ${p.pid}, status: ${p.status}') } - return } // stdin_write will write the string `s`, to the stdin pipe of the child process. @@ -290,6 +292,15 @@ fn (mut p Process) _signal_kill() { } } +// _signal_term - should not be called directly, except by p.signal_term +fn (mut p Process) _signal_term() { + $if windows { + p.win_term_process() + } $else { + p.unix_term_process() + } +} + // _signal_pgkill - should not be called directly, except by p.signal_pgkill fn (mut p Process) _signal_pgkill() { $if windows { @@ -323,5 +334,4 @@ pub fn (mut p Process) run() { return } p._spawn() - return } diff --git a/vlib/os/process_nix.c.v b/vlib/os/process_nix.c.v index 5592307dea1a47..150e0c830d1e1f 100644 --- a/vlib/os/process_nix.c.v +++ b/vlib/os/process_nix.c.v @@ -74,6 +74,10 @@ fn (mut p Process) unix_resume_process() { C.kill(p.pid, C.SIGCONT) } +fn (mut p Process) unix_term_process() { + C.kill(p.pid, C.SIGTERM) +} + fn (mut p Process) unix_kill_process() { C.kill(p.pid, C.SIGKILL) } @@ -127,6 +131,9 @@ fn (mut p Process) win_stop_process() { fn (mut p Process) win_resume_process() { } +fn (mut p Process) win_term_process() { +} + fn (mut p Process) win_kill_process() { } diff --git a/vlib/os/process_windows.c.v b/vlib/os/process_windows.c.v index 325e985f61aabe..3255c2e14a27d2 100644 --- a/vlib/os/process_windows.c.v +++ b/vlib/os/process_windows.c.v @@ -157,6 +157,10 @@ fn (mut p Process) win_kill_process() { C.TerminateProcess(wdata.proc_info.h_process, 3) } +fn (mut p Process) win_term_process() { + p.win_kill_process() +} + fn (mut p Process) win_kill_pgroup() { wdata := unsafe { &WProcess(p.wdata) } C.GenerateConsoleCtrlEvent(C.CTRL_BREAK_EVENT, wdata.proc_info.dw_process_id) @@ -279,6 +283,9 @@ fn (mut p Process) unix_stop_process() { fn (mut p Process) unix_resume_process() { } +fn (mut p Process) unix_term_process() { +} + fn (mut p Process) unix_kill_process() { }