xos

package
v0.25.15 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

GoKit - xos

OS kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xos"
)

Documentation

Visit the docs on GoDoc

Example

Get uid and gid of nobody
uid, gid, err := xos.LookupUser("nobody")
if err == nil {
    fmt.Println("uid=", uid, "gid=", gid)
}
Set process user to nobody
err := xos.SetUser("nobody")
if err != nil {
    fmt.Println("set user failed", err)
}

License

Copyright 2012-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPidExists is pid file exists
	ErrPidExists = errors.New("xos: process is running")
	// ErrPidLockFailed is pid lock failed
	ErrPidLockFailed = errors.New("xos: lock pid file failed")
)

Functions

func Author

func Author() string

Author returns package author

func Exec

func Exec(cmd string, args ...string) (stdout, stderr string, err error)

Exec exec command and returns

func GetProcPwd

func GetProcPwd() string

GetProcPwd returns the abs dir of current execution file

func GetPwd

func GetPwd() string

GetPwd returns the abs dir of current path

func Getenv added in v0.21.6

func Getenv(name, def string) string

Getenv returns system environment variable or default value

func License

func License() string

License returns package license

func LookupUser

func LookupUser(name string) (uid, gid int, err error)

LookupUser returns the uid and gid of user

func SetGID added in v0.25.4

func SetGID(gid int) (err error)

SetGID set the gid of process

func SetUID added in v0.25.4

func SetUID(uid int) (err error)

SetUID set the uid of process

func SetUser

func SetUser(user string) (err error)

SetUser Set process user

func TimeoutExec

func TimeoutExec(timeout int, cmd string, args ...string) (stdout, stderr string, err error)

TimeoutExec exec command with timeout and returns

func Version

func Version() string

Version returns package version

Types

type Pidx

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

Pidx storing pid info

func Pid

func Pid(f string) *Pidx

Pid init a new pid

func (*Pidx) Alive

func (p *Pidx) Alive() (int, error)

Alive returns pid is alive

func (*Pidx) Create

func (p *Pidx) Create() (int, error)

Create check create a new pid file

func (*Pidx) Value

func (p *Pidx) Value() (int, error)

Value returns pid value

Jump to

Keyboard shortcuts

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