How to display only the first 5 running process using top in shell scripting?
Here i used the top command inside a function,and i called the function.
when executing this bash file i get all the process which are using by the kernel
i just want to display only the first 5 running process.
is it possible?
This is not that easy, as it heavily depends on top's configuration, and on the tools that are available on your system (which, by the way, you fail to mention in your request). My best result on my linux system :
Use -d1 for e.g. FreeBSD...
You need one single iteration of top. With -n1, top leaves cleanly after that. Without it, it is killed because its output pipe has disappeared. Or, grep keeps waiting for more input...
Using top for this kind of task is generally a problem because top with its curses-designed interface was built for interactive use. You might want to consider using a different program.
For instance there is ps, which would also allow to sort for a more specific criteria than "whatever top places first". The process(es) with the most processor-time used? The processes with the most virtual memory allocated? The process using the most real memory? All this (and more) could be a realistic criteria for sorting (and identifying the top 5 of) the processes. With ps you do it this way:
First, look at the various arguments of the (SysV-style-)ps-option "-o" (see the man page): for this example i will use the size of the allocated virtual memory, which is "vsz". I make the virtual memory size the first column, then sort numerically on it. The output is from my system (Linux Fedora Core 22, Kernel 4.4.18):
Replace "vsz" by other arguments as your definition of "top" processes changes: "pcpu" for cpu consumption for instance, etc.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)