Giter Site home page Giter Site logo

Comments (3)

phil294 avatar phil294 commented on May 26, 2024

this should even be the default. the user can issue background jobs using & him/herself.

Edit: I dont know what I meant by that, foreground mode is already the default as mentioned by @joetwiddle below ??

from cpulimit.

jonathancross avatar jonathancross commented on May 26, 2024

I just use a bash function to do this:

function cpulimit () {
  PID=$1
  REST_TIME=${2}
  REST_TIME=${REST_TIME:=1.5}
  RUN_TIME=${3}
  RUN_TIME=${RUN_TIME:=1}
  if [ "$PID" ]; then
    echo "Starting: $(date) pid=$PID rest=${REST_TIME} run=${RUN_TIME}."
    while true; do
      kill -SIGSTOP ${PID}
      sleep ${REST_TIME}
      kill -SIGCONT ${PID}
      sleep ${RUN_TIME}
      echo -n .
    done
    echo -e "Done: $(date)"
    echo "  • You can use this to continue a stopped process: kill -SIGCONT ${PID}"
  else
    echo "ERROR: You must supply pid."
    echo "USAGE:   cpulimit pid <rest-sec> <run-sec>"
    echo "EXAMPLE: cpulimit 123456 1.5 1"
  fi
}

It will output . every cycle.
Just type ^c to kill the process.

Note: only tested recently on MacOS, but I see no reason it should not work on Linux.

from cpulimit.

joeytwiddle avatar joeytwiddle commented on May 26, 2024

@jonathancross That shellscript is pretty neat! Although I don't think it quite addresses the issue.

I think what @gavv wants is to specify the command to execute on the command-line, so they don't have to do any mangement of PIDs.

This would work really well with other tools, including trickle:

nice -n 15 ionice -c 3 trickle -d 20 -u 20 cpulimit -l 10 ./foo bar

Wait a minute. This is supported! Since 688fc58. See the last line below:

Usage: cpulimit [OPTIONS...] TARGET
   OPTIONS
      ...
   TARGET must be exactly one of these:
      -p, --pid=N            pid of the process (implies -z)
      -e, --exe=FILE         name of the executable program file or path name
      COMMAND [ARGS]         run this command and limit it (implies -z)

I believe this issue can be closed.

from cpulimit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.