lsof

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(w io.Writer, opts Options) error

Run executes the lsof command

func RunByPID

func RunByPID(w io.Writer, pid int, opts Options) error

RunByPID shows open files for a specific process (convenience function)

func RunByPort

func RunByPort(w io.Writer, port int, opts Options) error

RunByPort shows open files for a specific port (convenience function)

Types

type OpenFile

type OpenFile struct {
	Command    string `json:"command"`
	PID        int32  `json:"pid"`
	User       string `json:"user"`
	FD         string `json:"fd"`
	Type       string `json:"type"`
	Device     string `json:"device,omitempty"`
	Size       int64  `json:"size,omitempty"`
	Node       string `json:"node,omitempty"`
	Name       string `json:"name"`
	State      string `json:"state,omitempty"`
	Protocol   string `json:"protocol,omitempty"`
	LocalIP    string `json:"local_ip,omitempty"`
	LocalPort  uint32 `json:"local_port,omitempty"`
	RemoteIP   string `json:"remote_ip,omitempty"`
	RemotePort uint32 `json:"remote_port,omitempty"`
}

OpenFile represents an open file or network connection

type Options

type Options struct {
	PID         int    // -p: show files for specific PID
	User        string // -u: show files for specific user
	Port        int    // -i: show files using specific port
	Protocol    string // -i: filter by protocol (tcp, udp)
	Network     bool   // -i: show network files only
	Files       bool   // show file descriptors (default behavior)
	Command     string // -c: filter by command name prefix
	NoHeaders   bool   // -n: don't print headers
	JSON        bool   // -j: output as JSON
	IPv4        bool   // -4: show only IPv4
	IPv6        bool   // -6: show only IPv6
	Listen      bool   // show only listening sockets
	Established bool   // show only established connections
}

Options configures the lsof command behavior

Jump to

Keyboard shortcuts

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