views:

107

answers:

5

Hi All,

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 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

+1  A: 

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.

Ignacio Vazquez-Abrams
Perhaps OP has turned off overcommit?
ephemient
+1  A: 

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.

mark4o
A: 

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.

sckor
A: 

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.

shodanex
A: 

I tried with fork() and it gave me ENOMEM return value (Insufficient storage space is available).

Saurabh Shah