tags:

views:

60

answers:

5

hello guys, as you know there are two kind of process, i/o bound and cpu bound...

i need a cpu bound program that never terminates itself...

for example; is it like i wanted?

while(1){

    for(int i=0;i<1000; i++);

}
+2  A: 

First of all, why do you want a never terminating CPU bound program?

And yes, that would work, but you don't really need the inner for-loop. The while-loop will run forever on its own (assuming the compiler doesn't optimize it away).

siride
i will make a kernel module that focus on this never terminating program...so if i dont put inner loop, shouldnt it be "I/O bound program"???
That would not be a valid optimization since the control flow would be allowed to exit.
tster
@tstr: He might be thinking of where a variable reference is used in the while loop clause. The variable lookup could be optimized out, depending on some form of static analysis.
Merlyn Morgan-Graham
No, that wouldn't make it IO-bound since your program is still not doing any IO. Two levels of loops that do nothing is equivalent to a single loop that does nothing.
siride
@tster: I swear I've seen compilers optimize out empty loops. But I think those were all finite loops and I made an inductive leap (sigh).
siride
+2  A: 

for(;;); should do it!

mvds
Nice and to the point. About as concise as jmp $.
siride
A: 

i will make a kernel module that focus on this never terminating program... so if i dont put inner loop, shouldnt it be "I/O bound program"???

(you shouldn't follow up with an answer to your own question, it's against SO policy!)
mvds
ask questions by adding comments to answers, not other answers. I/O bound programs are programs whose performance bottleneck is I/O. Think of it this way -- would your program get faster if the CPU was faster? Would it get slower if the CPU was slower? Linearly? How about if you made your Hard Disk speed faster?
Lou Franco
@mvds: Huh? From the FAQ: "It's also perfectly fine to ask and answer your own question." Not that this is really an answer to the question.
Seamus Campbell
If you have an answer to the question, answer it (even if it's your question). If you have more questions, make comments or edit the question.
Lou Franco
@Seamus: Looks like you figured it out while typing that... I see at least three question marks in this "answer" so this is not an "answer to your own question". The policy is for good reason since there are now 3 places in this question to discuss things. way to go.
mvds
@mvds: "This isn't an answer" is a very different complaint than "you shouldn't follow up with an answer to your own question".
Seamus Campbell
@Seamus: if we're going to play lawyer here, also consider this definition of a "follow-up": "follow-up - an activity that *continues something that has already begun* or that *repeats something that has already been done*" (my emphasis). And "answer" in my statement refers to the (implicit) SO definition of "answer" - i.e. anything below a "question" that is not a comment. Besides the linguistics, I just don't see the added value of your statement, as we can all agree that this "answer" should not be standing here, because it is not an answer, but a further question.And you noted that already
mvds
I apologize if I'm misunderstanding you; the only reason I said anything at all is because your original comment here reads to me as a flat-out misstatement of SO policy. I'm honestly and sincerely not trying to be pedantic; I just don't want people to think that it is against the rules to answer their own question. Because it is not.
Seamus Campbell
A: 

There aren't only two kinds of processes. Even if you consider what resource is bounding the performance, there are more than two. The classic other ones are bandwidth, memory, database connections -- any finite resource or blocking one can be a bottleneck.

But, yes, your process is CPU-bound -- you can see that by looking at your task manager (Windows) or Activity Monitor (Mac) or top (Linux) and seeing it take 100% of your CPU.

Lou Franco
A: 

Those programs probably aren't CPU bound.

I suggest implementing the Sieve of Eratosthenes, or something like that. How about a program that takes a number (say 42), divides it by Pi 1000 times, multiplies it by Pi 1000 times, subtracts the result from the original number, adds it to a variable and increments a counter. Then repeat that indefinitely. I suppose you might overflow one of the numeric values, but that should be fixable / preventable.

Slartibartfast
You could also make a fork bomb, but while that would use CPU, it might very well cause your computer to crash / become unusable.
Slartibartfast
Why do you think his program isn't CPU-bound?
Lou Franco
Running such a program on my machine pushes CPU usage up to 100% (for the core it's running on). Seems pretty CPU bound to me.
siride