pidfd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const PPIDFD int = 3

PPIDFD is the first argument to waitid for pidfd.

Variables

This section is empty.

Functions

This section is empty.

Types

type Epoller

type Epoller struct {
	// contains filtered or unexported fields
}

Epoller is used to monitor PID file descriptors.

When the process that PID file descriptor refers to terminates, these interfaces indicate the file descriptor as readable. Then Epoller will close the PID file descriptor and call the callback.

func NewEpoller

func NewEpoller() (*Epoller, error)

func (*Epoller) Add

func (e *Epoller) Add(fd FD, onClose func() error) error

Add monitors the PID file descriptor and registers the onClose for it.

func (*Epoller) Close

func (e *Epoller) Close() error

Close stops the monitor.

func (*Epoller) Run

func (e *Epoller) Run() error

Run starts to monitor the event on PID file descriptor.

type FD

type FD int

func Open

func Open(pid uint32, flags int) (FD, error)

Open creates a file descriptor that refers to the process whose PID is specified in pid. The file descriptor is returned as the function result; the close-on-exec flag is set on the file descriptor.

https://man7.org/linux/man-pages/man2/pidfd_open.2.html

func (FD) GetFd

func (fd FD) GetFd(targetFD int, flags int) (int, error)

GetFd obtain a duplicate of another process's file descriptor.

func (FD) SendSignal

func (fd FD) SendSignal(signal unix.Signal, flags int) error

SendSignal sends a signal to a process specified by a file descriptor.

The flags argument is reserved for future use; currently, this argument must be specified as 0.

func (FD) Waitid

func (fd FD) Waitid(info *Siginfo, options int, rusage *Rusage) error

Waitid provides more precise control over which child state changes to wait for.

type Rusage

type Rusage = unix.Rusage

type Siginfo

type Siginfo struct {
	Signo int32
	Errno int32
	Code  int32

	Pid uint32
	// contains filtered or unexported fields
}

Siginfo extends the unix.Siginfo with Pid, which used to check the process state.

From https://man7.org/linux/man-pages/man2/waitid.2.html:

If WNOHANG was specified in options and there were no children in a waitable state, then waitid() returns 0 immediately and the state of the siginfo_t structure pointed to by infop depends on the implementation. To (portably) distinguish this case from that where a child was in a waitable state, zero out the si_pid field before the call and check for a nonzero value in this field after the call returns.

Jump to

Keyboard shortcuts

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