我在基于ARM的主板上运行以下代码:
void MainLoop()
{
char command[256];
int ret = 0;
int loopCount = 0;
while(1)
{
memset(command, '\0', sizeof(command));
sprintf(command, "/usr/bin/gst-launch-0.10 imxv4l2src ! imxv4l2sink &");
ret = system(command);
printf("StartStreamer: command=[%s], status:%d\n", command, ret);
if ( ret != 0 )
{
ret = system("reboot");
printf("Rebooting:%d\n", ret);
}
sleep(15);
memset(command, '\0', sizeof(command));
sprintf(command, "killall gst-launch-0.10");
ret = system(command);
printf("StopStreamer: command=[%s], status = %d\n", command, ret);
if ( ret != 0 )
{
ret = system("reboot");
printf("Rebooting:%d\n", ret);
}
sleep(15);
loopCount++;
printf("Loop Count:%d\n", loopCount);
}
}
运行一些随机循环后,我收到以下错误:
sh: out of memory
StartStreamer: command=[/usr/bin/gst-launch-0.10 imxv4l2src ! imxv4l2sink &], status:256
Segmentation fault
Rebooting:35584
StopStreamer: command=[killall gst-launch-0.10], status = 11
Rebooting:11
Loop Count:26
sh: relocation error: sh: symbol free, version GLIBC_2.4 not defined in file libc.so.6 with link time reference
sh: relocation error: sh: symbol free, version GLIBC_2.4 not defined in file libc.so.6 with link time reference
StartStreamer: command=[/usr/bin/gst-launch-0.10 imxv4l2src ! imxv4l2sink &], status:32512
Rebooting:11
killall: gst-launch-0.10: no process killed
StopStreamer: command=[killall gst-launch-0.10], status = 11
Rebooting:11
Loop Count:27
StartStreamer: command=[/usr/bin/gst-launch-0.10 imxv4l2src ! imxv4l2sink &], status:32512
Rebooting:32512
你能告诉我“sh:内存不足”是什么意思,是因为系统调用太多了..而且,我在glibc中得到重定位错误很奇怪......
我已经从C Application修改为Bash脚本:
#!/bin/ash
count=0
while [ true ];do
echo "Starting Streamer"
/usr/bin/gst-launch-0.10 imxv4l2src ! imxv4l2sink &
sleep 15
echo "Stopping Streamer"
killall gst-launch-0.10
sleep 15
count=$((count+1))
echo $count
done
在运行一些循环后,我得到以下错误:
* /bin/sh': double free or corruption (out): 0x0028ebf8 ***
*** Error in
/ bin / sh'出错:malloc():内存损坏:0x0028edf8 *
答案 0 :(得分:1)
请告诉我“sh:Out of Memory”是什么意思,是因为系统调用太多了。
来自system
手册页:
The system() library function uses fork(2) to create a child
process that executes the shell command specified in command using
execl(3) as follows:
execl("/bin/sh", "sh", "-c", command, (char *) 0);
system() returns after the command has been completed.
我会说这就是你看到这条信息的原因。你显然已经耗尽了fork
部分的资源。无论是运行到rlimit还是仅仅运行内存板(更有可能),这很难说。
所以基本上你有一个调用system
的主循环,它在“引擎盖下”创建了一个过程的副本,并将二进制文件(execl
部分)复制到副本中。哦,你尝试killall
第一个过程(再次由system
)。不幸的是,信号不能保证可靠,但通常会收到。另一个复杂因素是你受调度程序的支配,当你认为它可能不会运行该进程。
最好使用更原始的fork
/ exec
函数来访问此功能 - 至少你有PID发送信号而没有{{1的开销}}