gpt4 book ai didi

c - sh: 系统调用内存不足

转载 作者:太空宇宙 更新时间:2023-11-04 10:21:07 25 4
gpt4 key购买 nike

我在基于 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: Out of Memory”是什么意思吗,是不是因为太多的系统调用。另外,我在 glibc 中遇到重定位错误很奇怪......

我已将 C 应用程序修改为 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' 中的错误:双重释放或损坏(输出):0x0028ebf8 ***
***
/bin/sh' 中的错误:malloc():内存损坏:0x0028edf8 *

最佳答案

Can you please tell me what does "sh: Out of Memory" means, is it because of too many system calls.

来自 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 发送信号而无需killall 的开销。

关于c - sh: 系统调用内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43862376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com