Commands tagged cpu (19)

  • This will limit the average amount of CPU it consumes. Show Sample Output


    21
    sudo cpulimit -p pid -l 50
    Dhinesh · 2011-11-21 08:43:57 10
  • This is useful if you have a program which doesn't work well with multicore CPUs. With taskset you can set its CPU affinity to run on only one core.


    20
    taskset -c 0 your_command
    Alanceil · 2009-02-28 22:38:02 17
  • If shell escaping of the command is problematic, you can write the command to a file first: batch <somefile Or read it: read -re && echo "$REPLY" | batch Or, if your shell supports it, you can eliminate echo: read -re && batch <<<$REPLY ("man batch" lists 1.5 for me, but I don't know how widely it differs.)


    9
    echo 'some command' | batch
    kniht · 2010-07-14 03:08:31 3
  • For each cpu set mask and then monitor your cpu infos. Temp,load avg. etc. For example for 2nd cpu or 2nd core taskset 0x00000002 yes > /dev/null & For example for 3rd cpu or 3rd core taskset 0x00000004 yes > /dev/null & For example for 4th cpu or 4th core taskset 0x00000008 yes > /dev/null & Monitor your cpu temp with this command if you want watch -n1 "acpi -t" Load avg. from top command top kerim@bayner.com http://www.bayner.com/


    8
    taskset 0x00000001 yes > /dev/null &
    kerim · 2011-04-03 07:23:53 15

  • 7
    sudo lshw -C cpu|grep width
    sliceoflinux · 2009-09-24 11:43:00 6
  • [ 2000 -ge "$(free -m | awk '/buffers.cache:/ {print $4}')" ] returns true if less than 2000 MB of RAM are available, so adjust this number to your needs. [ $(echo "$(uptime | awk '{print $10}' | sed -e 's/,$//' -e 's/,/./') >= $(grep -c ^processor /proc/cpuinfo)" | bc) -eq 1 ] returns true if the current machine load is at least equal to the number of CPUs. If either of the tests returns true we wait 10 seconds and check again. If both tests return false, i.e. 2GB are available and machine load falls below number of CPUs, we start our command and save it's output in a text file. The ( ( ... ) & ) construct lets the command run in background even if we log out. See http://www.commandlinefu.com/commands/view/3115/ .


    4
    ( ( while [ 2000 -ge "$(free -m | awk '/buffers.cache:/ {print $4}')" ] || [ $(echo "$(uptime | awk '{print $10}' | sed -e 's/,$//' -e 's/,/./') >= $(grep -c ^processor /proc/cpuinfo)" | bc) -eq 1 ]; do sleep 10; done; my-command > output.txt ) & )
    michelsberg · 2010-07-13 09:12:11 3

  • 4
    slow2() { ionice -c3 renice -n 20 $(pstree `pidof $1` -p -a -u -A|gawk 'BEGIN{FS=","}{print $2}'|cut -f1 -d " ") ; }
    oernii3 · 2010-11-18 10:50:17 3

  • 4
    ps -ef --sort=-%cpu
    aguslr · 2011-10-14 21:57:51 3
  • Similar to `cpulimit`, although `prlimit` can be found shipped with recent util-linux. Example: limit CPU consumption to 10% for a math problem which ordinarily takes up 100% CPU: Before: bc -l <(echo "1234123412341234^12341234") See the difference `prlimit` makes: prlimit --cpu=10 bc -l <(echo "1234123412341234^12341234") To actually monitor the CPU usage, use `top`, `sar`, etc.. or: pidstat -C 'bc' -hur -p ALL 1


    4
    prlimit --cpu=10 sort -u hugefile
    mhs · 2013-02-27 15:59:11 7
  • There is no need for variables. I also added sleep to reduce cpu usage, however I didn't test it.


    3
    while :; do acpi -t | osd_cat -p bottom ; sleep 1; done &
    John_W · 2011-01-14 13:57:45 9
  • I've wanted this for a long time, finally just sat down and came up with it. This shows you the sorted output of ps in a pretty format perfect for cron or startup scripts. You can sort by changing the k -vsz to k -pmem for example to sort by memory instead. If you want a function, here's one from my http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html aa_top_ps(){ local T N=${1:-10};T=${2:-vsz}; ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -${T} -A|sed -u "/^ *PID/d;${N}q"; } Show Sample Output


    2
    command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'
    AskApache · 2010-05-18 18:41:38 6
  • Once you know the available frequencies for your CPU, they can be used to do things like set minimum CPU frequency for powerd so that it doesn't ramp down too slow on a server : /etc/sysctl.conf or /boot/loader.conf: debug.cpufreq.lowest=DESIRED FREQ HERE or at terminal sysctl debug.cpufreq.lowest=DESIRED FREQ HERE Show Sample Output


    2
    sysctl dev.cpu.0.freq_levels
    bugmenot · 2010-09-18 11:19:46 5
  • No need for a colon, and one less semicolon too. Also untested.


    1
    while sleep 1; do acpi -t | osd_cat -p bottom; done &
    linuts · 2011-01-14 23:22:57 4
  • Watch the temperatures of your CPU cores in real time at the command line. Press CONTROL+C to end. GORY DETAILS: Your computer needs to support sensors (many laptops, for example, do not). You'll need to install the lm-sensors package if it isn't already installed. And it helps to run the `sensors-detect` command to set up your sensor kernel modules first. At the very end of the sensors-detect interactive shell prompt, answer YES to add the new lines to the list of kernel modules loaded at boot. Show Sample Output


    1
    while :; do sensors|grep ^Core|while read x; do printf '% .23s\n' "$x"; done; sleep 1 && clear; done;
    linuxrawkstar · 2011-04-20 06:41:57 7
  • This version is precise and requires one second to collect statistics. Check sample output for a more generic version and also a remote computer invocation variant. It doesn't work with the busybox version of the 'top' command but can be adjusted Show Sample Output


    1
    top -bn2|awk -F, '/Cpu/{if (NR>4){print 100-gensub(/.([^ ]+).*/,"\\1","g",$4)}}'
    ichbins · 2014-04-18 17:48:05 6
  • # 4 cores with 2500 pi digits CPUBENCH 4 2500 . every core will use 100% cpu and you can see how fast they calculate it. if you do 50000 digitits and more it can take hours or days Show Sample Output


    1
    CPUBENCH() { local CPU="${1:-1}"; local SCALE="${2:-5000}"; { for LOOP in `seq 1 $CPU`; do { time echo "scale=${SCALE}; 4*a(1)" | bc -l -q | grep -v ^"[0-9]" & } ; done }; echo "Cores: $CPU"; echo "Digit: $SCALE" ;}
    emphazer · 2018-05-14 17:30:37 159
  • Using the output of 'ps' to determine CPU usage is misleading, as the CPU column in 'ps' shows CPU usage per process over the entire lifetime of the process. In order to get *current* CPU usage (without scraping a top screen) you need to pull some numbers from /proc/stat. Here, we take two readings, once second apart, determine how much IDLE time was spent across all CPUs, divide by the number of CPUs, and then subtract from 100 to get non-idle time. Show Sample Output


    0
    NUMCPUS=`grep ^proc /proc/cpuinfo | wc -l`; FIRST=`cat /proc/stat | awk '/^cpu / {print $5}'`; sleep 1; SECOND=`cat /proc/stat | awk '/^cpu / {print $5}'`; USED=`echo 2 k 100 $SECOND $FIRST - $NUMCPUS / - p | dc`; echo ${USED}% CPU Usage
    toxick · 2012-10-02 03:57:51 6

  • -1
    ps aux | awk {'sum+=$3;print sum'} | tail -n 1
    tailot · 2011-07-16 16:16:59 3
  • Broken in two parts, first get the number of cores with cat /proc/cpuinfo |grep proc|wc -l and create a integer sequence with that number (xargs seq), then have GNU parallel loop that many times over the given command. Cheers! Show Sample Output


    -2
    time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "scale=4000\; a\(1\)\*4" '|' bc -l
    kostis · 2018-12-06 05:15:24 673

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: