Find the answer to your Linux question:
Results 1 to 3 of 3

Thread: Using CPU

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Using CPU

    I am teaching high school students Linux and we are learning about the ps and top commands. I was wondering if anyone has a simple, short script that would use a fair amount of cpu (possibly in an infinite loop?) so that I could demonstrate how we look for this and how to "kill" it?
    I can write looping scripts, but can't seem to get any of them to use cpu.
    Thanks in advance!

  2. #2
    while [ 1 ] ; do
        # Force some computation even if it is useless to actually work the CPU
        echo $((13**99)) 1>/dev/null 2>&1
    That is for infinite loop script file.

    bash -c 'for (( I=100000000000000000000 ; I>=0 ; I++ )) ; do echo $(( I+I*I )) & echo $(( I*I-I )) & echo $(( I-I*I*I )) & echo $(( I+I*I*I )) ; done' &>/dev/null
    in terminal only using bash . You must leave that terminal open though to kill the process in htop or top though.
    I refuse to let fear and fear of others rule my life. It puts my humanity at risk.
    Accepting Death is the only way to stay alive.

  3. #3
    Or with this easy and clean commands within a running shell:
    while true ; do true; done
    Or in a proper bash script
    while true ; do

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts