How to check memory used by a process in Linux? - linux

How do I check the memory used by a process at same instance. Input provided is process NAME or ID. Need to know the actual memory used by the process at runtime.
What command should I enter to get result.

You have multiple options to find out the actual memory consumption for eg.
top (memory/cpu stats), free ( used/unused memory),mpstat ( cpu stats). Although,
I'd like to mention the following as it suits your requirement.
top p process_id

Try this one:
ps -e -orss=,args= | sort -b -k1,1n

You can use general and for particular user,
General: top
For Particular User: top -U username

Related

Linux / CentOS - Need to monitor a specific process

Please help.
So, I'm given a task to monitor a particular process in CentOS.
There are certain requirements.
Can't monitor using PID, because once process is killed or dead, solution is of no use.
It'll be great if I could know how much is the consumption of each thread of a process.
I've researched enough but with no success.
Thanks in advance.
I am uncertain what exactly you are trying to achieve, but this is how I would proceed:
Suggested Approaches
Multiple Process IDs per process name
top -H -p $(pgrep <process_name> | paste -s -d, -)
Single Process ID per process name
top -H -p $(pgrep <process_name>)
Further reading
Reuse command output
Thread Monitoring with top
Turn stdout into comma-separated string
Suggestion
Maybe think about implementing a solution like Prometheus with Node Exporter or Zabbix or Nagios.

Can I specify one CPU core while using oProfile?

I need to do a performance counter analysis on a 8-core server using oProfile, can oProfile only record events on core 7? Thank you!
The operf man page does not describe such an option (which would seem like the --cpu option of the perf record command).
With operf you can try the --separate-cpu / -c option (This option categorizes samples by cpu) with the --system-wide option (This option is for performing a system-wide profile.), and then provide a cpu:cpulist profile specification for opreport (Only consider profiles for the given numbered CPU).
For example:
$ sudo operf --separate-cpu --system-wide
... <Ctrl-C or kill -SIGINT>
$ opreport cpu:0

extract total HD memory and HD memory usage with linux command top

I'm looking forward to extract disk memory usage from top command using grep command an save it into a variable available for the bash interpreter.
... and I assume you failed to grep those part from top's output without understanding why...
This happens to many users, the reason is that the top command has a somewhat unexpected output strategy. It does make sense, once you dig into it, but as said, unexpected:
By default, top does not write it's output to stdout which is the precondition so that you can grep through it's output. However if you take a look into it's man page (man top), then you will spot the -b flag you can use to invoke it such that it does write it's output to stdout. This enables you to process the output as you are used to under unixoid environments, for example by "grepping" parts of the output for further usage.
Together with the -n flag which allows you to limit the commands output to a single iteration (again: see the man page) you can construct a simple extraction command:
top -b -n 1|grep "KiB"
I think from here on you will find the way by yourself :-) Have fun!
top provides no information about your hard disk usage.
Take a look at df.

See how much memory my program used in Terminal

I know when I type time ./myProgram <input.txt >output.txt on the terminal, once my program finish running, I can see the runtime conveniently. There must be some similar command to see memory usage of the program right? Please inform me concisely. Thanks!
One way to tell how much memory the terminal is using at any one time is to use top and:
find the line that corresponds to the terminal's process.
find the column that corresponds to memory usage (man top could likely tell you -- I'm on a Windows machine right now, and can't easily look it up.)
Perhaps try this command:
top | grep terminal
('terminal' can be replaced with 'xterm' or whatever terminal program you use)
Again, this will tell you the memory usage of a program at a particular time.

Getting Linux process resource usage (cpu,disk,network)

I want to use the /proc to find the resource usage of a particular process every second. The resources include cputime, disk usage and network usage. I looked at /proc/pid/stat , but I am not sure whether I am getting the required details. I want all 3 resource usage and I want to monitor them every second.
Some newer kernels have /proc/<pid_of_process>/io file. This is where IO stats are.
It is not documented in man proc, but you can try to figure out the numbers yourself.
Hope it helps.
Alex.
getrusage() accomplishes cpu, memory and disk etc.
man 2 getrusage
I don't know about network.
checkout glances.
It's got cpu disk and network all on one screen. It's not per process but it's better than looking at 3 separate tools.
Don't think there is a way to get the disk and network information on a per process basis.
The best you can have is the global disk and network, and the per process CPU time.
All documented in man proc
netstat -an
Shows all connections to the server including the source and destination ips and ports if you have proper permissions.
ac
Prints statistics about users' connect time
The best way to approach problems like this is to look up the source code of tools that perform similar monitoring and reporting.
Although there is no guarantee that they are using /proc directly, they will lead you to an efficient way to tackle the problem.
For your case, top(1), iotop(8) and nethogs(8) come to mind.
You can use SAR
-x report statistics for a given process.
See this for more details:
http://www.linuxcommand.org/man_pages/sar1.html
Example:
sar -u -r -b 1 -X PID | grep -v Average | grep -v Linux
You can use top
SYNOPSIS
top -hv|-bcHiOSs -d delay -n limit -u|U user -p PID -o champ -w [columns]
This is a screen capture of top in a terminal

Resources