Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-29
6
Medium Priority
?
218 Views
Last Modified: 2010-04-21
Hi!!

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


Paridhi
0
Comment
Question by:zoomtosara
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 8263007
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.
0
 

Author Comment

by:zoomtosara
ID: 8275873
HI!!

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 machines..at 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...

Paridhi
0
 
LVL 5

Accepted Solution

by:
bryanh earned 300 total points
ID: 8276299
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.
0
 

Author Comment

by:zoomtosara
ID: 8290542
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 intensive...it's just few comparisons......

Paridhi
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10225219
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question