forkexec

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: GPL-3.0, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ITimerReal    = 0
	ITimerVirtual = 1
	ITimerProf    = 2
)

定义ITimer的常量

View Source
const DarwinSafeStackSize = 65500

DarwinSafeStackSize darwin safe stack size

Variables

This section is empty.

Functions

func ForkExec

func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)

ForkExec Combination of fork and exec, careful to be thread safe.

func GetPipe

func GetPipe() ([]uintptr, error)

获取管道数据

func Pipe2

func Pipe2(p []int, flags int) (err error)

func StartProcess

func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error)

StartProcess wraps ForkExec for package os.

Types

type ExecRLimit

type ExecRLimit struct {
	TimeLimit     int // 时间限制 (ms)
	RealTimeLimit int // 真实时间限制 (ms, 触发SIGALRM)
	MemoryLimit   int // 内存限制 (KB)
	FileSizeLimit int // 文件读写限制 (B)
	StackLimit    int // 栈大小限制 (KB,0表示用内存限制的值,-1表示不限制,建议设置为2倍。Mac下有坑,不要去设置。)
}

ExecRLimit Exec rlimit options

type ITimerVal

type ITimerVal struct {
	ItInterval TimeVal
	ItValue    TimeVal
}

ITimerVal Itimer value struct

type ProcAttr

type ProcAttr struct {
	Dir   string    // Current working directory.
	Env   []string  // Environment.
	Files []uintptr // File descriptors.
	Sys   *SysProcAttr
}

ProcAttr holds attributes that will be applied to a new process started by StartProcess.

type RLimit

type RLimit struct {
	Which  int
	Enable bool
	RLim   syscall.Rlimit
}

RLimit rlimit strcut

type RlimitOptions

type RlimitOptions struct {
	Rlimits     []RLimit
	ITimerValue ITimerVal
}

RlimitOptions rlimit options

func GetRlimitOptions

func GetRlimitOptions(sysRlimit *ExecRLimit) *RlimitOptions

GetRlimitOptions 解析ExecRLimit结构体并获取setrlimit操作需要的信息

type SysProcAttr

type SysProcAttr struct {
	Chroot     string              // Chroot.
	Credential *syscall.Credential // Credential.
	// Ptrace tells the child to call ptrace(PTRACE_TRACEME).
	// Call runtime.LockOSThread before starting a process with this set,
	// and don't call UnlockOSThread until done with PtraceSyscall calls.
	Ptrace bool
	Setsid bool // Create session.
	// Setpgid sets the process group ID of the child to Pgid,
	// or, if Pgid == 0, to the new child's process ID.
	Setpgid bool
	// Setctty sets the controlling terminal of the child to
	// file descriptor Ctty. Ctty must be a descriptor number
	// in the child process: an index into ProcAttr.Files.
	// This is only meaningful if Setsid is true.
	Setctty bool
	Noctty  bool // Detach fd 0 from controlling terminal
	Ctty    int  // Controlling TTY fd
	// Foreground places the child process group in the foreground.
	// This implies Setpgid. The Ctty field must be set to
	// the descriptor of the controlling TTY.
	// Unlike Setctty, in this case Ctty must be a descriptor
	// number in the parent process.
	Foreground   bool
	Pgid         int                    // Child's process group ID if Setpgid.
	Pdeathsig    syscall.Signal         // Signal that the process will get when its parent dies (Linux only)
	Cloneflags   uintptr                // Flags for clone calls (Linux only)
	Unshareflags uintptr                // Flags for unshare calls (Linux only)
	UidMappings  []syscall.SysProcIDMap // User ID mappings for user namespaces.
	GidMappings  []syscall.SysProcIDMap // Group ID mappings for user namespaces.
	// GidMappingsEnableSetgroups enabling setgroups syscall.
	// If false, then setgroups syscall will be disabled for the child process.
	// This parameter is no-op if GidMappings == nil. Otherwise for unprivileged
	// users this should be set to false for mappings work.
	GidMappingsEnableSetgroups bool
	AmbientCaps                []uintptr  // Ambient capabilities (Linux only)
	Rlimit                     ExecRLimit // Set child's rlimit.
}

type TimeVal

type TimeVal struct {
	TvSec  uint64
	TvUsec uint64
}

TimeVal Timer value struct

Jump to

Keyboard shortcuts

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