Check the main memory usage by a linux command [closed] - linux

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 9 years ago.
Improve this question
Is there any command that I could use to check the memory usage for a single linux command? For instance I have a script file (test.sh) which will read and extract word from a 100mb text file. How could I know how much memory does this command (./test.sh input_file.txt) would take?
Thanks for the advises there!!

Use the free command to check the usage of RAM.
To check the size of the program in memory you can check the /proc/[pid]/statm file. For details of the format of this file read man proc
Fetch the PID of the script from the script using the $$ variable (in bash).
EDIT
Other solutions:
ps u $PID | tail -n1 | tr -s ' ' | cut -d ' ' -f 5,6 Gives you the VMZ and RSS of the process with $PID.
Or may want to like to see only the process memory using
watch -n0.5 ps u $PID
this will update the usage of the memory for your process every 0.5 secs. Adjust the value for updating as required.

You can just use top to see that. When you execute your script, a shell process such as bash, will be create to execute the script for you. So, find the shell process in top and you can see how many memory it uses.

Related

unlimited scrolling up from default linux command line [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 7 years ago.
Improve this question
I am looking to increase the default size of the scrolling up buffer from linux command line. It is a Debian server without gui.
I don't find related option in bashrc and I don't even know if there is other configuration file for the default prompt alt+f1 alt+f2 ...
You can change the scrollback-buffer size using kernel options as described here: https://wiki.archlinux.org/index.php/Scrollback_buffer .
However, if you are interested in the output of a command but at the same time you want to watch the command's progress interactively I suggest to use tee:
command | tee out.file
or if you want to append to a file use
command | tee -a out.file
tee is nice! use it! :)

Is it possible to update a varible from one shell to another shell? [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 9 years ago.
Improve this question
How can we update a variable from one shell to another shell ?
Suppose , I am having 2 Putty sessions opened , I want to set a variable in the first SHELL and I need that variable to access from the 2nd SHELL .
Is is possible ?
You can save the variable to a script.
Then source the script in the 2nd session.
For example:
# session 1
hello=world
echo "hello=$hello" > /tmp/var.sh
# session 2
. /tmp/var.sh
echo $hello
As each process' environment is protected, there's no way to share environment variables. I would suggest using a file on a shared filesystem to store the variable you want and reading that file in whenever you'd need to know what the new value is.
It is usually not possible, because each shell (and each process) has its own environment. See execve(2).
However, you might want to switch to the fish shell. It gives you so called universal variables which might be shared between several instances of (i.e. processes running) the fish shell. This is implemented thru the fishd user daemon (with which every fish process communicates).

Unix command for picking out run commands [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 9 years ago.
Improve this question
I am relatively new to linux environment. My doubt is this:
I run a lot of commands of various types , so when ever i want to rerun a old one i have to look through the entire history. is there any bash command that displays just the commands that begin with a particular combination of characters( my case here is i just want a list of all the ./ eg: ./ifv_script , ./run_regression i've run from the terminal)
Three methods:
You can grep your current history, e.g.:
$ history | grep ifv
You can also recall commands from the history by typing ControlR and then type a few characters from the command.
Finally you can grep your saved history file for older invocations from previous sessions, e.g.:
$ grep ifv ~/.bash_history
Just press Ctrl+R, and you will enter into reverse-i-search mode.
Now you can type a few characters that appear anywhere in the command and bash will start finding matches.
Final approach (bash only):
history | grep term

How to fetch cpu utilization of a particular 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 8 years ago.
Improve this question
I have used following command to fetch the CPU utilization of a process. It is giving result, but it is not coming out. I have used following command.
top | grep <processname>
I just want to put this in a loop and I will insert sleep in the code so that I can fetch the value in regular intervals
Use top's batch mode, eg.
top -b -n1 | grep processname
You can do:
while [ 1 ]; do top -n 1 | grep something; sleep 1; done
Use the -n option of top:
-n
Number of iterations. Update the display this number of times and then exit.

Finding which process was killed by Linux OOM killer [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 1 year ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
When Linux runs out of memory (OOM), the OOM killer chooses a process to kill based on some heuristics (it's an interesting read: http://lwn.net/Articles/317814/).
How can one programmatically determine which processes have recently been killed by the OOM killer?
Try this so you don't need to worry about where your logs are:
dmesg -T | egrep -i 'killed process'
-T, --ctime - Print human-readable timestamps.
Try this out:
grep -i 'killed process' /var/log/messages
Now dstat provides the feature to find out in your running system which process is candidate for getting killed by oom mechanism
dstat --top-oom
--out-of-memory---
kill score
java 77
java 77
java 77
and as per man page
--top-oom
show process that will be killed by OOM the first
Try this out:
grep "Killed process" /var/log/syslog

Resources