terminator

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 8 Imported by: 0

README

terminator

Library to stop processes gracefully, even on Windows.

Capabilities

On Windows it can:

  • Send Ctrl + C to console applications
  • Send Ctrl + Break to console applications
  • Close graphical applications as if it's window was closed
  • Send messages to standard input of console applications to answer the questions such as "Y/N?"

On Linux and macOS it can:

  • Send signals (SIGINT, SIGKILL etc.) to terminal applications
  • Send messages to standard input of terminal applications to answer the questions such as "Y/N?"

Not tested on other systems.

Usage

See examples folder and info on go packages.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlatChildTree

func FlatChildTree(pid int, withRoot bool) ([]*process.Process, error)

FlatChildTree returns gopsutil Process instances of all descendants of a process with the specified PID `pid`.

The first element is deepest descendant. The last one is a progenitor or closest child.

If the `withRoot` argument is set to true, add root process to the end.

func GetTerm added in v1.1.0

func GetTerm(pid int) (string, error)

GetTerm returns TTY device of the process with PID `pid`.

func Kill

func Kill(pid int) error

Kill is the same as KillWithContext with background context.

func KillWithContext

func KillWithContext(ctx context.Context, pid int) error

KillWithContext kills process with PID `pid` using context `ctx`.

func SendMessage

func SendMessage(pid int, msg string) error

SendMessage is the same as SendMessageWithContext with background context.

func SendMessageWithContext

func SendMessageWithContext(ctx context.Context, pid int, msg string) error

SendMessageWithContext writes a `msg` message to the console process with PID `pid` using context `ctx`.

`msg` must end with "\n" on Linux and with "\r" on macOS to be sent.

Requires root privilegies (e.g. run as sudo).

func SendSigTerm

func SendSigTerm(pid int) error

SendSigTerm is the same as SendSigTermWithContext with background context.

func SendSigTermWithContext

func SendSigTermWithContext(ctx context.Context, pid int) error

SendSigTermWithContext sends SIGTERM signal to the process with PID `pid` using context `ctx`.

func SendSignal

func SendSignal(pid int, sig syscall.Signal) error

SendSignal is the same as SendSignalWithContext with background context.

func SendSignalWithContext

func SendSignalWithContext(ctx context.Context, pid int, sig syscall.Signal) error

SendSignalWithContext sends signal `sig` to the process with PID `pid` using context `ctx`.

func WaitForProcStop

func WaitForProcStop(ctx context.Context, pid int)

WaitForProcStop returns when process with PID `pid` is no longer running or `ctx` deadline exceedes.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL