Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2013
    Posts
    2

    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
    Linux Guru rokytnji's Avatar
    Join Date
    Jul 2008
    Location
    Desert
    Posts
    4,036
    Code:
    #!/bin/bash
    while [ 1 ] ; do
        # Force some computation even if it is useless to actually work the CPU
        echo $((13**99)) 1>/dev/null 2>&1
    done
    That is for infinite loop script file.

    Code:
    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.
    Linux Registered User # 475019
    Lead,Follow, or get the heck out of the way. I Have a Masters in Raising Hell
    Tech Books
    Free Linux Books
    Newbie Guide
    Courses at Home

  3. #3
    Just Joined!
    Join Date
    Sep 2012
    Posts
    1
    Or with this easy and clean commands within a running shell:
    Code:
    while true ; do true; done
    Or in a proper bash script
    Code:
    #!/bin/bash
    while true ; do
      true;
    done

Posting Permissions

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