Command for finding process using too much CPU [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
What command can I use to find a process that's using a lot of CPU? Can I do this without installing something new?

Or using a few other utils you could do:
ps aux | sort -rk 3,3 | head -n 5
Change the value of head to get the number of processes you want to see.

Try doing this :
top -b -n1 -c
And if you want the process that takes the most %CPU times :
top -b -n1 -c | awk '/PID *USER/{print;getline;print}'
or
top -b -n1 -c | grep -A 2 '^$'

Related

How to get from a file exactly what I want in Linux? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
How to get from a file exactly what I want in Linux?
I have: 123456789012,refid2141,test1,test2,test3 and I want this: 123456789012 or 123456789012 test3.
$ echo "123456789012,refid2141,test1,test2,test3" | awk -F "," '{print $1}'
123456789012
$ echo "123456789012,refid2141,test1,test2,test3" | awk -F "," '{printf("%s, %s", $1,$5)}'
123456789012, test3
foo.csv:
123456789012,refid2141,test1,test2,test3
import csv
with open("foo.csv", "rt") as fd:
data = list(csv.reader(fd))
print(data[0][0])
For a bash solution:
cat foo.csv | cut -d',' -f1

Bash Console putting some invisible chars into string var [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Below I shared my console. I want to cut some string from output of some commands.
But there are 17 extra chars which I have no idea where comes from.
Can someone pls explain to me?
$ ls -al | grep total | sed 's/[[:blank:]].*$//' | wc -m
23
$ ns="total"
$ echo $ns | sed 's/[[:blank:]].*$//' | wc -c
6
But there are 17 extra chars which I have no idea where comes from.
Those are ANSI escape codes that grep uses for coloring matching substrings. You probably have an alias (run alias | grep grep to examine) like
alias grep='grep --color=always'
somewhere that causes grep to color matches even if output is not a tty, or something similar.
Try
ls -al | grep --color=never total | sed 's/[[:blank:]].*$//' | wc -m
and you'll get six.

Highest CPU utilisation process in linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want find highest cpu utilisation process.I am using
ps -aux|awk -F " " '{print $2" ,"$3}'|sort -r | head -5
Please help me if this is right or wrong command.I am getting 'Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ'
ps aux --sort %cpu | tail -n 1
user 5627 7.6 16.0 1928396 1331680 ? Sl Mar12 120:58 /opt/firefox/firefox
-n 1 gives the highest, adjust number to give highest x processes. Tail because default (+) for --sort is lowest to highest.
To get just the top cpu itself though that's not particularly useful:
ps aux --sort %cpu | tail -n 1 |awk '{print $3}'
7.6
To get it with the headers use highest to lowest (-) sort:
ps aux --sort -%cpu | head -n 2
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 5627 7.6 16.0 1928396 1331680 ? Sl Mar12 120:58 /opt/firefox/firefox

how to kill all processed from "lsof -i" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
How do I kill all processes returned from the following?
lsof -i
I have tried the following to no avail:
lsof -i | awk '{print $2}' | kill
kill takes PID's as its arguments whereas when you pipe it, it goes to the stdin of kill.
Pass them as arguments:
kill $(lsof -i | awk '{print $2}')

Is something wrong with my use of wc or grep in the linux command line? I"m getting +1 on my char count [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
When I run
echo "obase=2;3" | bc | grep -v \n\s | wc -m
bash returns 3. But when I run
echo "obase=2;3" | bc
bash returns 11.
Why is wc -m one digit high on its count?
The extra character is the trailing newline.
wc -m receives and counts the following three characters: 1 1 \n.
$ echo "obase=2;3" | bc | grep -v \n\s | od -c
0000000 1 1 \n
0000003
If you get rid of the newline, the count will be as you're expecting:
$ echo "obase=2;3" | bc | grep -v \n\s | tr -d '\n' | wc -m
2

Resources