如何让bash脚本执行的命令的进程id? [英] How to get the process id of command executed in bash script?
问题描述
我有一个剧本我想运行两个程序在同一时间,一个是C程序,另一种是请将CPULimit,我想在后台首先启动C程序&放大器;然后拿到C程序的PID,并把它交给请将CPULimit这也将在后台运行&放大器;
我想下面这样做,它只是启动的第一个程序和永远不会启动请将CPULimit。
另外,我在Arch Linux的使用systemd运行此作为启动脚本根。
#!/斌/庆典/ myprogram&安培;PID = $!请将CPULimit -z -p $ PID -l 75安培;退出0
我觉得我有这个现在解决了,根据这个位置:<一href=\"http://stackoverflow.com/questions/7686989/running-bash-commands-in-the-background-without-printing-job-and-process-ids\">link我需要包装的命令是这样的(命令)创建子壳。
#!/斌/庆典(mygprgram&安培;)
mypid = $!
(请将CPULimit -z -p $ mypid -l 75安培;)退出0
I have a script i want to run 2 programs at the same time, One is a c program and the other is cpulimit, I want to start the C program in the background first with "&" and then get the PID of the C program and hand it to cpulimit which will also run in the background with "&".
I tried doing this below and it just starts the first program and never starts cpulimit.
Also i am running this as a startup script as root using systemd in arch linux.
#!/bin/bash
/myprogram &
PID=$!
cpulimit -z -p $PID -l 75 &
exit 0
I think i have this solved now, According to this here: link I need to wrap the commands like this (command) to create a sub shell.
#!/bin/bash
(mygprgram &)
mypid=$!
(cpulimit -z -p $mypid -l 75 &)
exit 0
这篇关于如何让bash脚本执行的命令的进程id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!