How to display only the first 5 running process using top in shell scripting?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to display only the first 5 running process using top in shell scripting?
# 8  
Old 11-22-2016
I suppose one should also ask which way you want to sort your processes. Is it by CPU use at that instant, total CPU use since process start, real memory, virtual memory, IO read, IO writes, file opens, network traffic, is the server using swap heavily etc.

There are many things to consider when a server, application or process is running slowly which may not be a simple "who is using the most CPU?"

Some examples are:
  • if your code is frequently spawning new processes to perform a menial task (e.g. using echo $var | cut -f1 -d " " in a loop)
  • if your code repeatedly opens a file to read one item in a loop rather than opening the file as input to the loop
  • if your code appends single lines to a file in a loop rather than having one output file descriptor for the loop
  • and many other pitfalls I'm sure.

Is there a particular problem you are having that you need to find out why it's running slow? Some more general information about your server, application and your perceived problem may help us to work on a better answer.



Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display current directory for a running process for script

I'm trying to create a ksh script to do the following: 1) Ask the user what process they want to search for. 2) Have the script read the input as a variable and use it to search for the process. 3) Display the current time & date, the working directory of the process, and finally display the... (6 Replies)
Discussion started by: seekryts15
6 Replies

2. Shell Programming and Scripting

Need help in shell Scripting to display a output from a command

Please find my below requirement and see if you can help me on this. I am looking for a shell script which can provide me the below output. Manuall steps which i am doing now 1) First I source the File $ . ./WC_env.sh 2) Execute the command $ /app/oracle/product/mos/bin/mosotl -url... (2 Replies)
Discussion started by: sudheshpn@gmail
2 Replies

3. Shell Programming and Scripting

Display the First and Last name from a file using shell scripting

I am new to shell scripting and doing a similar thing @ work Stan:Smith:Detroit:MI Jim:Jones:Farmington Hills:MI Jack:Frost:Denver:CO Sue:Apple:New York:NY Cindy:Thompson:Battle Creek:MI John:Smith:Denver:CO George:Jones:New York:NY Need to create a shell script This script will display... (1 Reply)
Discussion started by: jakemathew
1 Replies

4. Shell Programming and Scripting

How to calculate months and display in shell scripting

I just want to know, how do we calculate the months in shell scripting. If i give the input as 20-01-2011, the output should be 20-02-2011, 20-03-2011 or 20-04-2011........ How do i get this ? Cheers. (6 Replies)
Discussion started by: sachin24
6 Replies

5. Shell Programming and Scripting

Shell script to display top 5 process (per cpu consumption)

Hello, I have to create shell script being myself real novice in scripting... I was looking on the Internet for some script examples, but I don't have the basic understanding of the shell. I was trying to do something with “ps” command without success. For exemple total number of... (2 Replies)
Discussion started by: mr_awd
2 Replies

6. UNIX for Dummies Questions & Answers

perl scripting for checking if a process is running

Hi All, I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output. I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar and then pass another variable... (2 Replies)
Discussion started by: pistachio
2 Replies

7. UNIX for Dummies Questions & Answers

Shell scripting adding text to top of file

Hi this is quite simple i am sure but without using awk or sed i need to add text to the top of a file this is what i have got so far #!bin/bash echo "Add text to top of file" read line echo $line >> file1 This adds the text to the bottom of the file can some1 please help cheers (7 Replies)
Discussion started by: meadhere
7 Replies

8. UNIX for Dummies Questions & Answers

top ten utilities in shell scripting?

Let's get some feedback about the top ten ute's you guys use in writing your scripts - I mean yeah it depends on the job and what you're trying to accomplish, but there ARE those commands (sed, grep, awk, cut, etc.) that most will use time and again... ...so, what do you use? (3 Replies)
Discussion started by: diego
3 Replies

9. UNIX for Advanced & Expert Users

Top running process

Hi, I have an oracle process running on top for a week now, but I couldnt see the same process with in oracle. how do I know what this process is? -GK P.S: when I say i didn't see within oracle, what I mean is I didn't see this process through oracle utility which shows all the oracle process (1 Reply)
Discussion started by: caprikar
1 Replies

10. UNIX for Dummies Questions & Answers

How Can I Have Top Display The Top 20 Processes??

how can i do that in a script withough havin the script halt at the section where the top command is located. am writign a script that will send me the out put of unx commands if the load average of a machine goes beyond the recommended number. top -n 20 i want to save this output to a file... (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question