LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2007, 12:16 PM   #1
sidra
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora Core 3, Red Hat 9, CentOS 4.2, Mandriva, Ret Hat Enterprise Linux 4.0
Posts: 116

Rep: Reputation: 15
script to get 100% cpu/disk usage


Hi all,

I want to create a test case by writing a script that will fill up the filesystem and lead to a crash. How can i accomplish this, script code? I also want to try and cause 100% cpu usage, how would i do this?

Thanks in advance.
 
Old 09-17-2007, 01:37 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
i thought in order to increase cpu usage/priority you have to have root access (is 100% even possible?). also, i dont know of a way to make such a script, because ive never had to think about it. since this seems malicious, i dont know how much help youll get.
 
Old 09-17-2007, 02:30 PM   #3
1slipperyfish
LQ Newbie
 
Registered: May 2007
Location: wigan
Distribution: mandriva
Posts: 29

Rep: Reputation: 15
if you're wanting a virus or a virus type of program try some of the hackers forums as they give them out for free, or have i got the question wrong?
paul
 
Old 09-17-2007, 02:58 PM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Just search this forum for 'fork bomb'. There is at least one thread that discusses them and gives examples.
 
Old 09-17-2007, 04:05 PM   #5
sidra
Member
 
Registered: Oct 2004
Location: USA
Distribution: Fedora Core 3, Red Hat 9, CentOS 4.2, Mandriva, Ret Hat Enterprise Linux 4.0
Posts: 116

Original Poster
Rep: Reputation: 15
Thanks! I actually filled up disk space very easily, resolved a bug i was working on. Will check out fork bomb!
 
Old 09-18-2007, 08:45 AM   #6
cconstantine
Member
 
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
super-fast way to fill your drive:
Code:
# cat /dev/null > /some/dir/somefile.txt
/dev/null is implemented within the system so the zero-bytes is produces are super-fast to read by cat. Throughput is limited by your filesystem I/O rate.
 
Old 09-18-2007, 03:48 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by cconstantine View Post
super-fast way to fill your drive:
Code:
# cat /dev/null > /some/dir/somefile.txt
/dev/null is implemented within the system so the zero-bytes is produces are super-fast to read by cat.
You certainly mean /dev/zero, not /dev/null which would just empty somefile.txt.
 
Old 09-18-2007, 03:52 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by nadroj View Post
i thought in order to increase cpu usage/priority you have to have root access (is 100% even possible?).
Actually, assuming your O/S is using a standard scheduler, a very simple script can load a CPU to 100% without any privilege requirements.

For multi-core / multi-thread CPUs, you need to run more than once the script to achieve 100% load.
 
Old 09-18-2007, 05:14 PM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
True, but not much use if you are trying to track interference to some other task - you really need something that isn't as easily pre-empted. I tend to use something like a stress test program - there are a few around.
I also generally use cpusets to contain the test to a subset of CPUs so I can monitor the effect(s) realtime without being locked out myself.
 
Old 09-19-2007, 04:26 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Here is something interesting (?)

it's 2 little perl scripts, one writes to the other through a pipe
something like:

buffer_write.pl -size=10000000 |buffer_read.pl

as the writer doesn't append a newline the reader never reads it.
so the internal buffer fills up and up and up and up.
eventually it fills up, interestingly on linux most often it brings the

OS to it's knees and you get a freeze up. With solaris however it
always chucks you off eventually with: Out of memory!






Code:
#!/usr/bin/perl  -s

# write to the stdout, but with no '\n' character causes
# the internal (stdio?) buffer to fill up.
# when used with the perl buffered <> operation
#
# use -size=n
#
# to increase the write


$main::size ||= 10_000;

$count;

sub do_write {

    $buf = chr int(rand(25)+65);
    $message = $buf x $size;
    $message .= "\n" if $line;;
    print "$message";           # no new line !!!
    $count += length $message;
    warn "$count bytes\n";
}

while ("hell" ne "frozen over") {

    do_write;
}
Code:
#!/usr/bin/perl -n

print length($_), "\n";
print;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FF 2.0 100% CPU Usage cexshun Slackware 12 04-05-2007 01:11 AM
CPU Usage goes to 100% when pthread_cond_wait is being used zen_buddha Linux - Software 4 10-19-2005 04:28 PM
CPU goes to (100% usage) without any task medo Linux - Hardware 4 04-19-2004 07:13 PM
CPU usage 100% ecsfan Red Hat 17 11-19-2003 03:06 PM
100 % CPU usage ???? rolandi Linux - Newbie 1 10-07-2003 11:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration