- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Script to hog CPU
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 11:05 AM
тАО12-18-2007 11:05 AM
Thanks,
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 11:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 11:15 AM
тАО12-18-2007 11:15 AM
Re: Script to hog CPU
#!/usr/bin/sh
while true
do
:
done
...this will run endlessly until killed. The colon ":" is a syntatically correct null statement.
Regards!
...JRF...
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 11:21 AM
тАО12-18-2007 11:21 AM
Re: Script to hog CPU
To add, if you want to run for a proscribed period of time, and have the process self-terminate, you can do:
# perl -e '$t=shift||60;$SIG{ALRM}=sub {exit};alarm $t;1 while {}'
By default this will run for 60-seconds. Pass any number of seconds as an argument to run shorter or longer before self-destructing.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 11:26 AM
тАО12-18-2007 11:26 AM
Re: Script to hog CPU
Thank you ! I used the while loop because it was basically what I 1st attempted but the ":" made the difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2007 07:30 PM
тАО12-18-2007 07:30 PM
Re: Script to hog CPU
The cpu-bound script is the same as the one James showed:
#!/usr/bin/sh
while :
do
:
done
Call the above script: cpu-bound
The script below will schedule up to 128 copies of cpu-bound. Just use CTRL-C to terminate the multi-cpu script and all the children will terminate.
#!/usr/bin/sh
# multi-cpubound
# Usage: multi-cpubound 10 script/prog_name [ "param(s)" [ nice or toggle ] ]
# Run a process or script multiple times with optional 50:50 nice
# Terminate multi-start to terminate all child processes
set -u
export PATH=/usr/bin
MYNAME=${0##*/}
SANEQTY=128
# F U N C T I O N S
function Usage
{
[ $# -gt 0 ] && echo "\n$@"
cat << EOF
Usage: $MYNAME QTY
where QTY=1 to $SANEQTY,
normal = all copies std priority
nice = all copies=nice,
toggle to alternate each copy
PROGNAME is program or script name
PARMS = program parameters or ""
EOF
exit 1
}
# M A I N P R O G R A M
# parameter handling/checking
[ $# -lt 3 ] && Usage "Requires 3 or more parameters"
QTY=$1
[ $QTY -lt 1 ] && QTY=1
[ $QTY -gt $SANEQTY ] && QTY=$SANEQTY
# find out the path used to start this prog
# if the PROGNAME has no directory path,
# use this program's path.
MYPATH=$(dirname $0)
PROGNAME="$MYPATH/$3"
if [ ! -x $PROGNAME ]
then
echo "\n$MYNAME: prog/script \"$PROGNAME\" not found\n"
exit
fi
# If parm#2 = normal, all procs=std pri
# If parm#2 = nice, all procs=nice
# If parm#2 = toggle, alternate procs start at nice
case $2 in
nice ) NICE=true
TOGGLE=false
;;
toggle ) NICE=false
TOGGLE=true
;;
normal ) NICE=false
TOGGLE=false
;;
* ) Usage "Requires 1 of: normal nice toggle"
esac
[ $# -gt 3 ] && PARMS="$@" || PARMS=""
COPY=0
NICE=false
# start the processes
echo "\nStarting $QTY copies of $PROGNAME $PARMS"
echo "$MYNAME PID = $$, NICE=$NICE toggle=$TOGGLE"
while [ $COPY -lt $QTY ]
do
let COPY=$COPY+1
if $TOGGLE
then
if [ $NICE = true ]
then
./$PROGNAME "$PARMS" &
NICE=false
else
nice ./$PROGNAME "$PARMS" &
NICE=true
fi
else
./$PROGNAME "$PARMS" &
fi
PIDS[$COPY]=$!
done
echo "Child PIDs = ${PIDS[@]}"
echo
trap 'echo "trap detected, stopping ${PIDS[@]}";kill ${PIDS[@]};exit' 1 2 3 15
# do nothing forever until terminated
while :
do
sleep 100
done
Bill Hassell, sysadmin