![](/img/trans.png)
[英]Why is there a difference in execution time while running the same program multiple times?
[英]Running a C program multiple times with different inputs each time
我需要一種方法在終端中運行 c 程序 256 次,操作號是 function 的輸入(即第三次運行它,輸入為 3)並找到程序不返回的輸入值分段錯誤。
您可以使用 bash 循環或使用 seq/xargs 進行多次執行
該代碼假定程序將以退出代碼零或崩潰結束。
# Bash
for ((i=1 ; i<=256 ; i++ )) do
if ! program $i > result.$i ; then
echo "Failed on $i"
fi
done
使用 seq/xargs,一個襯里
seq 1 256 | xargs -I@ program @ '||' echo "Failed on $@" \;
seq/xargs 的優點是您可以同時運行多個值 - 潛在的加速。
我認為 shell 腳本可能會對您有所幫助
#!/bin/bash
for i in 1 2 3 4 5
do
./program $i
exit_status=$?
if [ $exit_status -eq 127 ]; then
echo $i
fi
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.