【发布时间】:2021-10-18 21:06:11
【问题描述】:
我得到了一个程序,该程序一直运行到使用 ctrl + c 停止为止。我需要找到这个进程的 pid,然后使用 bash 脚本输出用户时间、系统时间和总时间等信息。我的理解是,为了做到这一点,我需要运行该进程,然后在脚本内停止它,在我停止程序后,我能够找到信息。我在停止脚本内的进程时遇到问题。
#!/bin/bash
clarg="$1"
if [ "$clarg" == "cpu" ] ; then
gcc -o cpu cpu.c
./cpu
#This is where I'm lost and tried this out from online but
#didn't work for me
trap "exit" INT
while :
do
sl -e
done
#Commands to find PID info below.
【问题讨论】:
-
您可以在后台运行它。然后PID将在
$!。