简体   繁体   English

作为守护程序运行时,Shell脚本不起作用

[英]Shell script does not work when run as daemon

I got a simple script (to measure CPU overhead) 我有一个简单的脚本(用于测量CPU开销)

#!/bin/bash

WAIT=2
i=1
while :
do
    # Obtain the cpu usage
    top -n 1 > t.$i

    i=$(($i+1))
    sleep $WAIT

done  

When I run it as 当我以

./Script.sh

It works as expected. 它按预期工作。

But when I run it as 但是当我以

./Script.sh&

it does nothing (files are not created). 它什么都不做(不创建文件)。 What am I missing here? 我在这里想念什么?

Change the line where you invoke top to be: 将调用top的行更改为:

top -b -n 1 > t.$i

This enables batch mode - good call Karoly 这将启用批处理模式-Karoly通话良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM