controlling SWAP mem and CPU Utilization thru C coding..disabling multi-user mode


I have a multi-threaded application(3 threads to be precise and 1 root thread)developed in C on linux..When i run this application, two threads use quite large amt of of CPU resources and abt 126 MB of my 128 MB RAM while swap is not at all used..Is it possible to include the code for controlling balance between swap and RAM being used in the application or is it some setting within some linux files????And how is possible to decrease the CPU utilization???

One more thing..i start my application using a shell script..i want whenever that shell script runs, user should be able to switch betwen screens using Ctrl-Alt-F1, etc(to disable multi-user mode)..How can that be done??i am able to find trapping interrupts like Ctrl Z but not this..

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First of all, you don't mention what else is going on in this system.  If there is nothing but these 3 threads, then it doesn't make any sense to try to reduce their resource utilization.  So I'm going to assume that there is something else in the system that you would like to have a greater share of real memory and CPU time.

The most basic way to control allocation of CPU time is with process priority.  See the section on process control in the GNU C library user's guide (usually 'info libc').  And 'man nice'.

There is no direct way to control a process' real memory allocation, but it tends to follow its CPU allocation.  The less a process runs, the less real memory it will have on average.

But reading your question again, it sounds like no swap space is getting used by anything, which means your system has enough real memory to fill everyone's needs, which means there's nothing you can do to stop the system from using the real memory.  Unused real memory is just a waste.

I don't have an answer for your other question.  Note:  EE works best when you post multiple questions as separate questions.
zoomtosaraAuthor Commented:

Thanx for ur reply..i have a tomcat server running on my system apart from my application...but that too doesn't consume any memory..what i have observed on various linux systems running proxy server, mail server, like applications is that they just use 2-3% of CPU resources and in case of memory also, both system RAM and SWAP are  used simultaneously(using top command) even though the RAM is free..

but in my case, the CPU resources are shown utilized abt 99% and no swap is used though just 28MB of RAM is shown free out of 128MB..i tried accessing tomcat from some client that moment, when a new java thread is started, the cpu utilization by the application threads gets reduced a little but then back to same(arnd 99%)..

so what i wnated to know is that is it the coding style because of which my application is utilizing such huge amount of cpu resources or some system setting...

First of all, take that "free" memory number with a grain of salt.  Linux frees up memory as it needs it; the amount free at this moment is not very meaningful.

Even if you have 0 "free" memory, it's normal to have no swap space used.  Back when memory was expensive, swapping was normal, but today there are lots of 128M systems that don't even _have_ swap space.

The 99% CPU usage is probably a problem, but the solution would more likely be in fixing the program so it demands less CPU time than in making Linux give it less.

What do the threads do?  One would expect them to wait for something (e.g. for a message on to arrive on a socket or for a signal from another thread to arrive), but instead they are constantly executing something.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zoomtosaraAuthor Commented:
Yes, the two threads are continuously monitoring one linked list each for specific entries before they delete those found matching...This is all these two threads are doing..
Can this be the cause of 99% memory utiization..but i don't think this execution is so much cpu's just few comparisons......

No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#8276299}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.