我正在尝试在运行其他进程时使用top
记录系统指标。我希望将事物链接在一起,就像这样:
#!/bin/bash
# Redirect `top` output
top -U $USER > file.txt &&
# Then run a process that just sleeps for 4 seconds
python3 -c 'import time;time.sleep(4)' &&
# Then run another process that does the same
python3 -c 'import time;time.sleep(4)'
但是,当我运行此命令时,后两个(Python)进程永远不会完成。我的目标是在其他任何进程开始之前从top
开始记录,然后一旦这些进程完成,就从top
停止记录。
答案 0 :(得分:1)
#run the first command in background
top -U $USER > file.txt &
# Then run a process that just sleeps for 4 seconds
python3 -c 'import time;time.sleep(4)' &&
# Then run another process that does the same
python3 -c 'import time;time.sleep(4)' &&
# kill the command in background
kill %1