本文整理汇总了Golang中syscall.Getpriority函数的典型用法代码示例。如果您正苦于以下问题:Golang Getpriority函数的具体用法?Golang Getpriority怎么用?Golang Getpriority使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Getpriority函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
log.SetFlags(0)
log.SetPrefix("nice: ")
flag.Usage = usage
flag.Parse()
xprio, err := syscall.Getpriority(syscall.PRIO_PROCESS, 0)
ck(err)
if flag.NArg() < 1 {
fmt.Println(xprio)
os.Exit(0)
}
err = syscall.Setpriority(syscall.PRIO_PROCESS, 0, *prio+xprio)
ck(err)
args := flag.Args()
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
ck(cmd.Run())
}
示例2: fillFromStat
func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, error) {
pid := p.Pid
statPath := common.HostProc(strconv.Itoa(int(pid)), "stat")
contents, err := ioutil.ReadFile(statPath)
if err != nil {
return "", 0, nil, 0, 0, err
}
fields := strings.Fields(string(contents))
i := 1
for !strings.HasSuffix(fields[i], ")") {
i++
}
termmap, err := getTerminalMap()
terminal := ""
if err == nil {
t, err := strconv.ParseUint(fields[i+5], 10, 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
terminal = termmap[t]
}
ppid, err := strconv.ParseInt(fields[i+2], 10, 32)
if err != nil {
return "", 0, nil, 0, 0, err
}
utime, err := strconv.ParseFloat(fields[i+12], 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
stime, err := strconv.ParseFloat(fields[i+13], 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
cpuTimes := &cpu.TimesStat{
CPU: "cpu",
User: float64(utime / ClockTicks),
System: float64(stime / ClockTicks),
}
bootTime, _ := host.BootTime()
t, err := strconv.ParseUint(fields[i+20], 10, 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
ctime := (t / uint64(ClockTicks)) + uint64(bootTime)
createTime := int64(ctime * 1000)
// p.Nice = mustParseInt32(fields[18])
// use syscall instead of parse Stat file
snice, _ := syscall.Getpriority(PrioProcess, int(pid))
nice := int32(snice) // FIXME: is this true?
return terminal, int32(ppid), cpuTimes, createTime, nice, nil
}
示例3: main
func main() {
app := cli.NewApp()
app.Name = Name
app.Version = Version
app.Author = "KUWASHIMA Yuichiro"
app.Email = "[email protected]"
app.Usage = "viagra [-d minutes] PID"
app.Flags = GlobalFlags
app.Commands = Commands
app.CommandNotFound = CommandNotFound
app.Action = func(c *cli.Context) {
var err error
var min int64
min, err = strconv.ParseInt(c.String("duration"), 10, 64)
if err != nil {
println("Duration is not number")
}
if len(c.Args()) > 0 {
var proc int
var preNice int
proc, err = strconv.Atoi(c.Args()[len(c.Args())-1])
if err != nil {
println("Proc no parse error")
return
}
preNice, err = syscall.Getpriority(syscall.PRIO_PROCESS, proc)
if err != nil {
println("Unknown PID")
return
}
err = syscall.Setpriority(syscall.PRIO_PROCESS, proc, 20)
if err != nil {
println("Setpriority failed")
return
}
println("Power up!")
timer := time.NewTimer(time.Duration(min) * time.Second)
<-timer.C
err = syscall.Setpriority(syscall.PRIO_PROCESS, proc, preNice)
println("Time is up!")
}
}
app.Run(os.Args)
}
示例4: main
func main() {
flag.Usage = usage
flag.Parse()
if flag.NArg() < 1 {
usage()
}
which := syscall.PRIO_PROCESS
if *gflag {
which = syscall.PRIO_PGRP
} else if *uflag {
which = syscall.PRIO_USER
}
for _, arg := range flag.Args() {
var n int
var err error
id := -1
if *uflag {
p, err := user.Lookup(arg)
if err == nil {
n, err = strconv.Atoi(p.Uid)
}
} else {
n, err = strconv.Atoi(arg)
}
if err == nil {
id = n
}
if id < 0 {
ek(fmt.Errorf("bad %q", arg))
continue
}
prio, err := syscall.Getpriority(which, id)
if ek(err) {
continue
}
ek(syscall.Setpriority(which, id, prio+*inc))
}
os.Exit(status)
}
示例5: fillFromStat
func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, error) {
pid := p.Pid
statPath := filepath.Join("/", "proc", strconv.Itoa(int(pid)), "stat")
contents, err := ioutil.ReadFile(statPath)
if err != nil {
return "", 0, nil, 0, 0, err
}
fields := strings.Fields(string(contents))
termmap, err := getTerminalMap()
terminal := ""
if err == nil {
terminal = termmap[mustParseUint64(fields[6])]
}
ppid := mustParseInt32(fields[3])
utime, _ := strconv.ParseFloat(fields[13], 64)
stime, _ := strconv.ParseFloat(fields[14], 64)
cpuTimes := &CPUTimesStat{
CPU: "cpu",
User: float32(utime * (1000 / CLOCK_TICKS)),
System: float32(stime * (1000 / CLOCK_TICKS)),
}
bootTime, _ := BootTime()
ctime := ((mustParseUint64(fields[21]) / uint64(CLOCK_TICKS)) + uint64(bootTime)) * 1000
createTime := int64(ctime)
// p.Nice = mustParseInt32(fields[18])
// use syscall instead of parse Stat file
snice, _ := syscall.Getpriority(PRIO_PROCESS, int(pid))
nice := int32(snice) // FIXME: is this true?
return terminal, ppid, cpuTimes, createTime, nice, nil
}