Linux 用bash脚本用valgrind检查内存

Linux 用bash脚本用valgrind检查内存,linux,bash,unix,ubuntu,Linux,Bash,Unix,Ubuntu,尝试让脚本检查内存是否泄漏或试图访问坏内存 我正在尝试这个脚本 但是没有运气,因为当程序编译时有警告,valgrind给了我“坏”状态,即使没有内存泄漏 #!/bin/bash #some varibles for the future output=${1} progname=${2} input=${3} trash="/dev/null" # execute the prog and putting output to out file valgrind --error-exitcode

尝试让脚本检查内存是否泄漏或试图访问坏内存

我正在尝试这个脚本 但是没有运气,因为当程序编译时有警告,valgrind给了我“坏”状态,即使没有内存泄漏

#!/bin/bash
#some varibles for the future
output=${1}
progname=${2}
input=${3}
trash="/dev/null"

# execute the prog and putting output to out file
valgrind --error-exitcode=1 ./${progname} < ${input} >${output} 2>&1

# grab exit status of valgrind (0 if all good ,1 if not)
ret=$?

# write appropriate message as per return status value
((ret == 0)) && echo "Memory V" || echo "Memory X"

# return the exit status of testMemory
exit $ret
我就是这样做的 我希望它能纠正所有的错误

#!/bin/bash

#some varibles for the future
output=${1}
progname=${2}
input=${3}
trash="/dev/null"

# execute the prog and putting output to out file
valgrind ./${progname} < ${input} >${output} 2>&1
# cheking for patters that indicate err
grep -q "ERROR SUMMARY: 0 errors" "$output"

# grab exit status of grep (0 if all good ,1 if not)
ret=$?

# write appropriate message as per return status value
((ret == 0)) && echo "Memory V" || echo "Memory X"

# return the exit status of testMem
exit $ret
#/bin/bash
#未来的一些变数
输出=${1}
progname=${2}
输入=${3}
trash=“/dev/null”
#执行prog并将输出输出到out文件
valgrind./${progname}<${input}>${output}2>&1
#检查指示错误的模式
grep-q“错误摘要:0个错误”“$output”
#grep的抓取退出状态(0如果全部正常,1如果不正常)
ret=$?
#根据返回状态值编写适当的消息
((ret==0))&&echo“Memory V”| | echo“Memory X”
#返回testMem的退出状态
退出$ret

“因为当程序编译时带有警告,它会给我“OK”状态”-wat?您甚至没有在脚本中编译…在显示的第二个脚本中,为什么要在“$input”文件中搜索错误模式?我认为您应该在“$output”文件中这样做。是的,您说得对,但仍然不起作用。请发布一些valgrind命令报告的“错误摘要”行的示例。如果您的程序以非零形式退出,即使没有valgrind错误,valgrind也将返回非零。
#!/bin/bash

#some varibles for the future
output=${1}
progname=${2}
input=${3}
trash="/dev/null"

# execute the prog and putting output to out file
valgrind ./${progname} < ${input} >${output} 2>&1
# cheking for patters that indicate err
grep -q "ERROR SUMMARY: 0 errors" "$output"

# grab exit status of grep (0 if all good ,1 if not)
ret=$?

# write appropriate message as per return status value
((ret == 0)) && echo "Memory V" || echo "Memory X"

# return the exit status of testMem
exit $ret