Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 我的bash脚本占用了太多内存_Linux_Bash_Memory Leaks - Fatal编程技术网

Linux 我的bash脚本占用了太多内存

Linux 我的bash脚本占用了太多内存,linux,bash,memory-leaks,Linux,Bash,Memory Leaks,我在寻找哪个程序正在使用我的内存,泄漏在哪里 而且,我发现,泄漏是在bash脚本 但是,这怎么可能呢?Bash脚本将始终为每个变量赋值分配新空间 我的bash脚本如下所示,请告诉我如何更正此问题 CONF="/conf/my.cfg" HIGHRES="/data/high.dat" getPeriod() { meas=`head -n 1 $CONF` statperiod=`echo $meas` } (while true do lastline=`tail -n 1

我在寻找哪个程序正在使用我的内存,泄漏在哪里

而且,我发现,泄漏是在bash脚本

但是,这怎么可能呢?Bash脚本将始终为每个变量赋值分配新空间

我的bash脚本如下所示,请告诉我如何更正此问题

CONF="/conf/my.cfg"
HIGHRES="/data/high.dat"

getPeriod()
{
meas=`head -n 1 $CONF`
statperiod=`echo $meas`
}

(while true
do
        lastline=`tail -n 1 $HIGHRES |cut -d"," -f2`
        linenumber=`grep -n $lastline $HIGHRES | cut -f1 -d:`
        /bin/stat $linenumber
        getPeriod
        sleep $statperiod
done)
编辑#1: high.dat的最后一行

2013-02-11,10:59:13,1,0,0,0,0,0,0,0,0,12.340000,0.330000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24.730000,24.709990,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

我无法用该脚本的近似值来验证内存泄漏,因此可能泄漏实际上并不是您认为的那样。考虑用更多的信息更新你的问题,包括一个完整的工作示例,以及你做了什么来找出内存泄漏。 也就是说,您选择了一种非常奇怪的方法来确定一个文件有多少行。最常用的方法是使用标准的
wc
工具:

$ wc -l < test.txt
      19
$

你在哪里设置$lastline?你能举例说明一下高.dat中的内容吗?
$ wc -l test.txt
      19 test.txt
$