开发者

Embedded linux child process creation problem

开发者 https://www.devze.com 2022-12-20 07:15 出处:网络
I am using linux kernel 2.6.30 on my board. It has 128MB of DDR2. My main application occupies almost 80MB of system memory.

I am using linux kernel 2.6.30 on my board. It has 128MB of DDR2. My main application occupies almost 80MB of system memory. After executing all applications, only 25MB is left. I want to execute system commands from my main application (which uses 80MB). But it is not executed. As per my understanding, each child process requires same memory as of parent process(i got this description from fork function manual). So in my case, new child process requires another 80MB which is not available. Hence system call is not working. System 开发者_JAVA技巧command must execute immediately after giving command as followed steps in main application requires result of system command (like need to store output of grep command in file and immediately read that file for further processing). Hence i can not use IPC mechanism. What are other ways?

Saurabh Shah


Unless you have some bizarre, broken CPU architecture or libc it should be using Copy-on-Write with fork(), so you should be fine with an exec() right after.


If you are using system() then it will need to execute the shell to parse and execute your command, and the shell could be large. If you can divide up the string into a command and arguments yourself then you can call fork() and execve() directly so that the shell would not need to be loaded.


You should try a simple fork first, and see what happens. I think I have met a similar problem, with a thttpd server running out of memory for no reason. Also a very useful tool, is strace.
strace your process, and you will be able to see what system call is failing, and provide more information to the people here.

Also, I can't see why IPC is not a solution. May be more complicated, but still a solution. For example you could use unix domain socket to get a bidirectionnal pipe.


If by some chance your embedded system has glib installed, you might try using their system call equivalents.

See: http://library.gnome.org/devel/glib/2.22/glib-Spawning-Processes.html

g_spawn_sync in particular seems to do what you need.

Unfortunately, the system() call is often difficult to get good error codes from. I think it would be worth trying a fork() and exec() (like the other posters suggested) to see if they return you a more detailed error code, and whether or not it's the fork() or exec() (or something else) which is failing.

If you can gather that additional info, it might help others to assist your debugging.

0

精彩评论

暂无评论...
验证码 换一张
取 消