473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Nice a tight loop?

Environment: Linux C program (gcc), on linux kernel 2.6.16

Is there any function I can put inside a tight loop in order to make
the process a little nicer. In that it will give at least the CPU
temporarily back to the OS so that it doesn't seem like the current
program is consuming 50% of cpu resource?

The said loop had to process 32 million records in an structure array
in memory, and when it goes into this loop. Well the system seems to
freeze. The original programmer/designer had long left the company.
We want to touch this piece of code as little as possible due to
time/resource constraint. Thanks.

Jul 7 '06 #1
16 2177
Joseph wrote:
Environment: Linux C program (gcc), on linux kernel 2.6.16

Is there any function I can put inside a tight loop in order to make
the process a little nicer. In that it will give at least the CPU
temporarily back to the OS so that it doesn't seem like the current
program is consuming 50% of cpu resource?

The said loop had to process 32 million records in an structure array
in memory, and when it goes into this loop. Well the system seems to
freeze. The original programmer/designer had long left the company.
We want to touch this piece of code as little as possible due to
time/resource constraint. Thanks.
OT here, try a Linux group, you will have to profile and find the cause.

--
Ian Collins.
Jul 7 '06 #2
Joseph said:
Environment: Linux C program (gcc), on linux kernel 2.6.16

Is there any function I can put inside a tight loop in order to make
the process a little nicer. In that it will give at least the CPU
temporarily back to the OS so that it doesn't seem like the current
program is consuming 50% of cpu resource?
Yes, there are at least two ways to spread the load, one programmatic and
one from within the shell. The C language itself doesn't have any specific
way to do this, so the details of your solution are off-topic here, but a
Linux group should be able to set you on the right road in fairly short
order. I suggest comp.os.linux.development.apps as a starting point. I
would guess that they would tell you about nice(1), sleep(3), and
usleep(3), but that's just a guess really.

Oh, btw, I know this sounds a bit obvious, but do bear in mind that yielding
the CPU will increase the runtime of the application!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #3
Joseph wrote:
Environment: Linux C program (gcc), on linux kernel 2.6.16

Is there any function I can put inside a tight loop in order to make
the process a little nicer. In that it will give at least the CPU
temporarily back to the OS so that it doesn't seem like the current
program is consuming 50% of cpu resource?

The said loop had to process 32 million records in an structure array
in memory, and when it goes into this loop. Well the system seems to
freeze. The original programmer/designer had long left the company.
We want to touch this piece of code as little as possible due to
time/resource constraint. Thanks.
out_of_topic {
I would suggest that there is something wrong with the system
then. On the Linux system I use there's often at least one
process taking at least 97% of cpu time and I notice no delay
in the system's response times for everyday jobs like text editing
for example. It certainly doesn't freeze.
}

Richard Heathfield wrote:
Yes, there are at least two ways to spread the load, one programmatic and
one from within the shell. The C language itself doesn't have any specific
way to do this, so the details of your solution are off-topic here, but a
Linux group should be able to set you on the right road in fairly short
order. I suggest comp.os.linux.development.apps as a starting point. I
would guess that they would tell you about nice(1), sleep(3), and
usleep(3), but that's just a guess really.
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.

Spiros Bousbouras

Jul 7 '06 #4
sp****@gmail.com writes:
[...]
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 7 '06 #5

Keith Thompson wrote:
sp****@gmail.com writes:
[...]
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.

Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)
Why do they call it ""Standard C Library Functions"" then ?

Jul 7 '06 #6
sp****@gmail.com said:

<snip>
>
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
The Solaris man pages do not define the C language. The C Standard does. And
it doesn't mention sleep or usleep in its library section. Therefore, they
are not standard C library functions.

The sleep function is, however, a POSIX function. (I don't believe that
usleep is POSIX - it appears to be a BSD function.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 7 '06 #7
sp****@gmail.com wrote:
Keith Thompson wrote:

>>sp****@gmail.com writes:
[...]
>>>Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.

Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)


Why do they call it ""Standard C Library Functions"" then ?
Because they live in the Solaris's standard library.

--
Ian Collins.
Jul 7 '06 #8

Richard Heathfield wrote:
sp****@gmail.com said:

<snip>

Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.

The Solaris man pages do not define the C language. The C Standard does.
I'm aware of that. I was simply assuming that when the Solaris man
pages say
"standard" they mean in the C standard. I guess I was wrong.

Jul 7 '06 #9
sp****@gmail.com wrote:
>
Joseph wrote:
[...]
program is consuming 50% of cpu resource?

The said loop had to process 32 million records in an structure array
in memory, and when it goes into this loop. Well the system seems to
[...]
out_of_topic {
I would suggest that there is something wrong with the system
then. On the Linux system I use there's often at least one
process taking at least 97% of cpu time and I notice no delay
in the system's response times for everyday jobs like text editing
for example. It certainly doesn't freeze.
Apparently, many people have learned / been taught that "a system
should never go to 100% CPU usage". Our company has had many
support calls/e-mails over the years from people complaining that
"something is wrong" because the CPU usage goes to 100% when they
run a report or build an index, even when using "nice". Well, I
would hope that a CPU-bound operation, such as an in-memory sort
would cause the system to go to 100% usage. (If not, then the
system is wasting _my_ time by sitting idle when it could be
sorting.) They can't seem to grasp the concept that "100% usage"
doesn't mean "starving all the other processes", but rather
"using all of the otherwise-idle time".
}
[...]
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Jul 7 '06 #10
sp****@gmail.com writes:
Richard Heathfield wrote:
sp****@gmail.com said:

<snip>
>
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
The Solaris man pages do not define the C language. The C Standard does.

I'm aware of that. I was simply assuming that when the Solaris man
pages say
"standard" they mean in the C standard. I guess I was wrong.
My Linux man pages say:

$ man 3 sleep:
Linux Programmer's Manual
bla bla bla
CONFORMING TO
POSIX.1

$ man usleep
Linux Programmer's Manual
bla bla bla
CONFORMING TO
4.3BSD. The SUSv2 version return int, and this is also the
prototype used by glibc 2.2.2. Only the EINVAL error return is
documented by SUSv2.

$ man 3 printf
Linux Programmer's Manual
bla bla bla
CONFORMING TO
.....(printf functions) functions conform to ANSI X3.159-1989
(``ANSI C'') and ISO/IEC 9899:1999 (``ISO C99'')... (a lot more
information snipped).

Is there a CONFORMING TO section in your Solaris man pages? If yes,
that will tell you where the function is coming from.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Jul 7 '06 #11
sp****@gmail.com wrote:
Keith Thompson wrote:
>sp****@gmail.com writes:
[...]
>>Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)

Why do they call it ""Standard C Library Functions"" then ?
My company has created and maintained a boatload of "standard C library
functions" and they have nothing to do with ISO C. There is also a
POSIX standard; this is what we often consider our "standard" in our
documentation, when we refer to such functions outside of the context of
ISO C.
Jul 7 '06 #12
Nelu <sp*******@gmail.comwrites:
sp****@gmail.com writes:
>Richard Heathfield wrote:
sp****@gmail.com said:
<snip>
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
The Solaris man pages do not define the C language. The C Standard does.
I'm aware of that. I was simply assuming that when the Solaris man
pages say "standard" they mean in the C standard. I guess I was
wrong.
[snip]
Is there a CONFORMING TO section in your Solaris man pages? If yes,
that will tell you where the function is coming from.
Alas, there isn't (at least not on my Solaris 9 system).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 7 '06 #13
Keith Thompson <ks***@mib.orgwrites:
Nelu <sp*******@gmail.comwrites:
sp****@gmail.com writes:
Richard Heathfield wrote:
sp****@gmail.com said:
<snip>
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
The Solaris man pages do not define the C language. The C Standard does.
I'm aware of that. I was simply assuming that when the Solaris man
pages say "standard" they mean in the C standard. I guess I was
wrong.
[snip]
Is there a CONFORMING TO section in your Solaris man pages? If yes,
that will tell you where the function is coming from.

Alas, there isn't (at least not on my Solaris 9 system).
I used to have access to a SUN Sparc (U10?) running Solaris 7, but it
was replaced with an IBM PC so I couldn't check it anymore. I refuse
to install Solaris on x86 :-).

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Jul 7 '06 #14
Clever Monkey wrote:
sp****@gmail.com wrote:
Keith Thompson wrote:
sp****@gmail.com writes:
[...]
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)
Why do they call it ""Standard C Library Functions"" then ?
My company has created and maintained a boatload of "standard C library
functions" and they have nothing to do with ISO C. There is also a
POSIX standard; this is what we often consider our "standard" in our
documentation, when we refer to such functions outside of the context of
ISO C.
I hope then that your documentation documents which standard it refers
to when using the word standard. Otherwise people might get the wrong
idea.

Keith Thompson wrote:
Nelu <sp*******@gmail.comwrites:
sp****@gmail.com writes:
Richard Heathfield wrote:
sp****@gmail.com said:
<snip>
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
The Solaris man pages do not define the C language. The C Standard does.
I'm aware of that. I was simply assuming that when the Solaris man
pages say "standard" they mean in the C standard. I guess I was
wrong.
[snip]
Is there a CONFORMING TO section in your Solaris man pages? If yes,
that will tell you where the function is coming from.

Alas, there isn't (at least not on my Solaris 9 system).
Solaris 8 doesn't either. But it does mention when the function comes
from BSD.

My confusion was due to the fact that on every other occasion when I
checked the Solaris man page for some C function and it said that it
was standard , then the function was part of the C standard.

Jul 7 '06 #15
sp****@gmail.com wrote:
Clever Monkey wrote:
>sp****@gmail.com wrote:
>>Keith Thompson wrote:

sp****@gmail.com writes:
[...]
Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.
Nope.

That section of man pages is titled "Standard C Library Functions";
that doesn't imply that they're all defined by the C standard. (Or,
if it does, it's wrong.)
Why do they call it ""Standard C Library Functions"" then ?
My company has created and maintained a boatload of "standard C library
functions" and they have nothing to do with ISO C. There is also a
POSIX standard; this is what we often consider our "standard" in our
documentation, when we refer to such functions outside of the context of
ISO C.

I hope then that your documentation documents which standard it refers
to when using the word standard. Otherwise people might get the wrong
idea.
Our man pages do, along the same lines as the "conformance" sections
discussed else-thread. We have a large library we use internally, and a
big set of commercial tools and libraries to provide analogs to
"standard" libraries for systems that do not (traditionally) have them
(where standard is defined as any number of standards organizations and
levels). This is less common now, but was a real problem for Win32 and
mainframe developers in the past.

But, yes, conformance to specific standards is documented fully in our
customer facing stuff. Internal APIs and libraries mention standards
only when a comment discusses a function, feature or bugfix in the
context of a specific standard or (quite often) RFC section.
Jul 7 '06 #16
sp****@gmail.com wrote:
Richard Heathfield wrote:

>>sp****@gmail.com said:

<snip>
>>>Aren't sleep and usleep standard C ? The Solaris man pages seem to
think so.

The Solaris man pages do not define the C language. The C Standard does.


I'm aware of that. I was simply assuming that when the Solaris man
pages say
"standard" they mean in the C standard. I guess I was wrong.
Solaris is a POSIX system, so 'standard' in the man pages means POSIX/SUSv3.

--
Ian Collins.
Jul 7 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C GIllespie | last post by:
Dear All, I have two equal size lists - list1, list2. Basically, each item in list 1 has a partner in list2. I was wanting to do something like So if: list1= list2= then if I did this 'for...
1
by: Richard A. DeVenezia | last post by:
A page has a long running computation loop. While in the loop I want to update a status object so I know how things are going in the computation. This is what I have, but it doesn't seem to...
4
by: Nick | last post by:
Dear All, I have a section of code that is something along the lines of: private void threadFunc () { while (true) { object o = ourOwnQueueObject.GetObject (); // Non blocking....
4
by: Alex Stevens | last post by:
Well, It's 4:10 on Friday Afternoon and I am now in a state of turmoil....... I've just spoken with a trainer (who's opinion would be in far higher regard than mine), and he's just told me that...
19
by: Charles Law | last post by:
Take a solution with a project hierarchy along the lines of an n-tier system, so that we have a data layer, business layer and presentation layer. The presentation layer is coupled to the business...
0
by: AnandaSim | last post by:
Hi All, I'm looking around for a tool or component that will allow me to: 1. Visually design a layout for pdf output - the layout would have graphic and text elements, tight positioning...
1
by: robinsand | last post by:
I am a new C++ programmer. I am still having trouble with certain data types and constructors, among other things. I'm not sure if I've used "std::string" properly throughout this program. I need...
3
by: darrel | last post by:
Maybe I'm overgeneralizing--and correct me if I am--but why does it seem that ASP.net web hosts are so tight when it comes to disk storage space? I'm OK paying more for ASP.net hosting, as I...
0
by: comp.lang.php | last post by:
if (!function_exists('memory_get_usage')) { /** * Determine the amount of memory you are allowed to have * * @access public * @return long * @see actual_path * @link...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.