• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

College assigment

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

G-PHoRCe

Member
Joined
Aug 15, 2001
Location
Harlem, New York
Well I'm kind of embarrassed but i need some help. I'm taking a Networking class (among others) at a local college here but the las assignment or at least this part of the it got me beat.


Programming: Write a C, C++, or Java program that causes the CPU utilization to approach 100% for an extended period. Submit the source code in hard copy.

Ive never took a programming class ever and now I've been asked to make a program in a network class. I plan on learning of course but i only have a week to do so. I'm not to sure of what is the learning curve but any help doing such a program would be greatly appreciated.

In addition I've emailed the professor to let him know that I'm a total noob when it comes to programming. I'm waiting for his answer but in the meanwhile i will do my best on my side to make that program. hopefully that prof will understand my situation.
 
ummm infinite loop! lol...Can't you just somehow set the program to be active for a certain amount of time and making a big infinite loop in it?
 
G-PHoRCe said:
Well I'm kind of embarrassed but i need some help. I'm taking a Networking class (among others) at a local college here but the las assignment or at least this part of the it got me beat.




Ive never took a programming class ever and now I've been asked to make a program in a network class. I plan on learning of course but i only have a week to do so. I'm not to sure of what is the learning curve but any help doing such a program would be greatly appreciated.

In addition I've emailed the professor to let him know that I'm a total noob when it comes to programming. I'm waiting for his answer but in the meanwhile i will do my best on my side to make that program. hopefully that prof will understand my situation.

Well for a start we know we are going to preform arithmetic operations over and over again so maybe a loop is needed.
 
WhatTheSchmidt said:
ummm infinite loop! lol...Can't you just somehow set the program to be active for a certain amount of time and making a big infinite loop in it?
And around and around it goes, when it will stop nobody knows.

You may want to fork() a bunch of processes ALL running infinite loops...since a simple arithmetic loop doesn't actually drive most modern multi-tasked OSes into 100% CPU mode.
 
infinite loop of double recursion calls will though ^_^ ex. akermann function. I had fun with that one, I got 100% cpu utilization and memor usage with it a couple of big numbers lol.
 
just do
Code:
while(1)
{}
Without any optimizations (so set NO optimizations) it will run at a 100% CPU usage on a single core. It will just be running in a loop pointlessly. Even if you have a 9GHz CPU it will just be going over that loop REALLY FAST! :D

I thought the only way to make a program NOT use 100% single core CPU is to have sleep() in it....
 
Confirmed, simple while loop in Windows on a signle core with no optimization will take 100% CPU utilization.

And if your next assigment will be 'eat as much RAM as possible', then request free RAM amount from OS and then malloc all of it. :beer:

Dude, is it just me, or does your class sounds really fun?
 

Attachments

  • yep.JPG
    yep.JPG
    120.3 KB · Views: 237
ShadowPho said:
Confirmed, simple while loop in Windows on a signle core with no optimization will take 100% CPU utilization.
You can even leave optimizations on (I have mine set to O2 by default) and it'll work. On top of that, if you leave out the headers as well (since you don't need them) you get a nice compact 15KB file. ;)
 
Soichiro said:
You can even leave optimizations on (I have mine set to O2 by default) and it'll work. On top of that, if you leave out the headers as well (since you don't need them) you get a nice compact 15KB file. ;)

15 KB?????!??! Thats what a file with "lbl1: jmp lbl1;" compiles into????? where does it get 15,000 bytes from????? :mad:

/me goes to see how low can he go
 
Well, if you leave the standard dev-c++ includes in, it compiles to 463KB. Turning off optimizations doesn't affect file size.

15kbwhileloop.png
 
Last edited:
Bad news...

I'm dropping the class (operating system). I will take some programming class before i take this class again. C# here i come!!!

thank you for your time guys.
 
Soichiro said:
How did you get yours so much smaller than mine? D;
I told it to strip and gave it a $20 bill. :beer:
Set "strip executable" to 1

I'm dropping the class (operating system). I will take some programming class before i take this class again. C# here i come!!!

thank you for your time guys.

I tried C# and VB, but I found good ol' C/C++ to be much easier for me. I started off abut 4 years ago learning BASIC, and then ASM. By the time I got to C++, I LOVED it. Its prolly just me, but it seems that C is really straightrowrard and really simple which turns into not so simple once you get into pointers, but still really nice.
 
G-PHoRCe said:
I'm dropping the class (operating system). I will take some programming class before i take this class again. C# here i come!!!

thank you for your time guys.
C# is for squares. Real pro-grammers use C. The brave ones use C++, and the ones looking to optimize their lives on the command line use Ruby or Perl. But real pro-grammers abhor C#.

edit: hmm, that's entirely too simple a solution, but it actually works, even with
Code:
doug@piper ~/src $ gcc -O3 -funroll-loops hang.c -o hang
 
Captain Newbie said:
edit: hmm, that's entirely too simple a solution, but it actually works, even with
Code:
doug@piper ~/src $ gcc -O3 -funroll-loops hang.c -o hang
I think that his prof was going to talk about how not to program programs. So maybe he was going to show that in order not to take the 100% cpu utilization you gotta sleep()...
 
wow, they had you do some C programming in a operating systems class? hell, all i did in my OS class was learn unix and DOS commands, along with a little xp installations and 98/2k

the only programming ive done so far is VB.net required for my degree, and i never want to touch visual basic 2005 express again :(
 
OS is the hardest class in my field at my uni... I fear and await the day that I take that class, for then I shall have become the uber-PC nerd.

15-410, Operating System Design & Implementation, is a programming-intensive OS class. The core experience is writing a small Unix-inspired OS kernel, in C with some x86 assembly language, which runs on a PC hardware simulator called Simics (and on actual PC hardware if you wish). Work is done in two-person teams, and "team programming" skills (source control, modularity, documentation) are emphasized. Core concepts include the process model, virtual memory, threads, synchronization, and deadlock. The course includes one medium-sized non-textbook reading assignment with a writing component. If you have already completed an implementation-intensive OS class (one based on, e.g., NACHOS), ECE's Embedded Systems class might be a better opportunity for growth. Finally, past experience suggests that 15-410 is a challenging class. Students who successfully complete it will learn a lot, but it will not be easy.
 
Java will spit out a 265 byte class file, but then you've got to lug that huge JRE around :D

Code:
public class WhileLoop {
	public static void main(String[] args) {
		while(true);
	}
}

JigPu
 
Back