Problem with process resources, not hardware limitations.
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Problem with process resources, not hardware limitations.
Hi All,
I am writting some application on embedded device, that has to use mplayer. I want to call mplayer by using system() call, which seems the easiest. However (of course when sufficient number of modules is loaded - significant part of memory is used), I get the error saying "Cannot allocate memory". So this is kind of reasonable I can't do it. However I can call mplayer from within a console and all is fine.
So I thought there may be some issues concerning process limits. So I tried to changed them (such as RLIMIT_NPROC, RLIMIT_AS and few more)(on application startup), by invoking setrlimit (also checked if they were changed by getrlimit, later) and this didn't help.
Maybe some of You do know the solution, how I can make mplayer playing, because this is not a limitation of the hardware, obviously.
Thank You for any response and hint.
Regards,
Krzysztof.
One general thought is that system() tends to work by running another instance of the shell, which may not be the best choice in a embedded situation. One thing you can try to troubleshoot, is to write a program that you run in place of mplayer, that instead displays current resource limits and resource utilization/availability.
It looks like you tried to summarize the situation, but the details may be needed to solve the problem.
For example, when you call mplayer from a console, do you have all the modules to which you referred, also loaded? Exactly which resource limits do you set? For example, in this situation changing NPROC should probably only be an afterthought.
One general thought is that system() tends to work by running another instance of the shell, which may not be the best choice in a embedded situation. One thing you can try to troubleshoot, is to write a program that you run in place of mplayer, that instead displays current resource limits and resource utilization/availability.
This won't work, since even calling ifconfig doesn't work, when starting mplayer doesn't work.
When I observe "top" results, while playing with my application, mplayer loads correctly, if application takes less than 270m of VSZ. Otherwise, it fails to load with mentioned error.
Quote:
For example, when you call mplayer from a console, do you have all the modules to which you referred, also loaded? Exactly which resource limits do you set? For example, in this situation changing NPROC should probably only be an afterthought.
So I just played around and tried some variations of values that differ with those on my pc (where application never fails).I know that they shouldn't be the same, because these are different types of hardware, but I gave it a try. Also I took into account descriptions in manual of setrlimit. But as I mention, none of them seemed to work.
Thank You for being concerned. If You have any ideas, please share them with me. All the best!
Krzysztof.
system() is effectively a wrapper for fork() and exec(), and system() creates a shell, then runs the command you request on that shell. Ergo, system() uses more memory than just using fork() and exec() directly on the specific command that you wish to run without running another copy of the shell.
So, first, try using fork() and exec() to directly execute a program, don't use system().
Secondly, realize that any thing such as we've been discussing to run another process, creates a duplicate of various memory consuming resources from the original process. You can control that duplication to some extent.
So if you just want to run mplayer, if you don't need all the resources you may have open right before running mplayer, do things such as, look at the man page on fcntl for the usage of FD_CLOEXEC. If you are using a third party GUI toolkit/library/etc., you may not know exactly what resources it uses, you can use something like lsof to determine what resources you may be able to dispense of in the process copy to save memory.
Secondly, realize that any thing such as we've been discussing to run another process, creates a duplicate of various memory consuming resources from the original process. You can control that duplication to some extent.
So if you just want to run mplayer, if you don't need all the resources you may have open right before running mplayer, do things such as, look at the man page on fcntl for the usage of FD_CLOEXEC. If you are using a third party GUI toolkit/library/etc., you may not know exactly what resources it uses, you can use something like lsof to determine what resources you may be able to dispense of in the process copy to save memory.
Sir, thank You for Your help.
I haven't solved it fully but it gave me some impuls and I am trying to get things done. Thank You once more, all the best.
How about peeling one layer of the onion? As already noted, system() starts a shell. What happens if you run a shellscript with the same command on the embedded system? Unless the system is very tight on resources, a system resource limit is unlikely, especially as you can run the command from a console. What sort of console -- terminal emulator under X or ... ? Perhaps there is something about the command environment that does not suit the command such as access to the necessary graphical environment. Assuming X, perhaps you need something like export DISPLAY='localhost:0.0' and for the X display user to authorise with Xauthority (sorry -- recollection of details hazy).
So the distribution is Angstrom and there is no graphical environment installed. Therefore, this limitation You wrote about is not about to happen, am I right? Thank You for ideas
So the distribution is Angstrom and there is no graphical environment installed. Therefore, this limitation You wrote about is not about to happen, am I right? Thank You for ideas
IDK Angstrom but if there is no graphical environment, how can mplayer play video? Surely I am not understanding something here!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.