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 3 years ago.
Improve this question
I want to log memory usage every 5th second and hence I am using free -s 5 -m> memory.log
How to add timestamp before every lie in this log?
Expected output:
Tue Jan 21 06:50:44 UTC 2020
total used free shared buffers cached
Mem: 7809 6268 1540 0 57 3497
-/+ buffers/cache: 2713 5095
Swap: 0 0 0
Tue Jan 21 06:50:49 UTC 2020
total used free shared buffers cached
Mem: 7809 6268 1540 0 57 3497
-/+ buffers/cache: 2713 5095
Swap: 0 0 0
I found out that there is no single line command to do that and this can be achieved by writing and executing a script.
So the shell script is:
#!/bin/bash -e
echo " date time $(free -m | grep total | sed -E 's/^ (.*)/\1/g')" >> /var/log/memory_utilisation.log
while true; do
echo "$(date '+%Y-%m-%d %H:%M:%S') $(free -m | grep Mem: | sed 's/Mem://g')" >> /var/log/memory_utilisation.log
sleep 5
done
Related
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 months ago.
Improve this question
when I use docker run -itd mysql,then to use ps -elf check the process infomation with "4 S systemd+ 257584 257561 1 80 0 - 712611 poll_s Jul17 ? 00:40:16 mysqld".
root#xx:/proc/257584/ns# ps -elf | grep mysqld
4 S systemd+ 257584 257561 1 80 0 - 712611 poll_s Jul17 ? 00:40:20 mysqld
root#xx:/proc/257584/ns# ps -el | grep mysqld
4 S 999 257584 257561 1 80 0 - 712611 poll_s ? 00:40:21 mysqld
But I use "cat /cat/passwd" can't find username equal to "systemd+".
docker Version: 20.10.12
os ubuntu20.04
ps (sadly) trims the username to 8 (if i'm counting right) characters and adds a + after the user name initial part. The username could be systemd-mysql or systemd-something that you can find in passwd.
From manual:
If the length of the username is greater than the length of the display column, the username will be truncated. See the -o and -O formatting options to customize length
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 2 years ago.
Improve this question
I was trying to find out, how do i get the pid, process name, command line of the current terminal(what is running in the background and got started with that terminal)?
By running:
echo $$
15925
You will get the process ID of your current session. Using this process ID, you can then run:
ps -ef | grep 15925
foo 14870 15925 0 10:32 pts/6 00:00:00 sleep 120
foo 14871 15925 0 10:32 pts/6 00:00:00 ps -ef
foo 14872 15925 0 10:32 pts/6 00:00:00 grep --color=auto 15925
foo 15925 15919 0 Nov23 pts/6 00:00:08 -bash
The second column will show the parent process (15925) and the second the parent
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 would like to capture the output of the top command to use in another program however I only need certain information, more precisely I only need the USER, PID, CPU, COMMAND columns.
I already have the command top -b -n 1 | sed -n '7,12p' to filter the top 5 results but I cannot go any further because I do not know much about sed/awk.
Example: here is what I get
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4 root 20 0 98748 50608 4608 S 6.4 4.9 212:12.16 X
1 root 20 0 2132 128 96 S 0.0 0.0 0:07.62 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 7:28.54 ksoftirqd/0
and here is what i want
PID USER %CPU COMMAND
4 root 6.4 X
1 root 0.0 init
2 root 0.0 kthreadd
3 root 0.0 ksoftirqd/0
pass to:
awk '{print $1,$2,$9,$NF}'
Everything combined.
top -b -n 1 | awk 'NR>6 && NR<13 {printf "%6s %-4s %-4s %-s\n",$1,$2,$9,$NF}'
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
I would like to get the available memory reported as a percentage using a Linux command line.
I used the free command, but that is only giving me numbers, and there is no option for percentage.
Using the free command:
% free
total used free shared buffers cached
Mem: 2061712 490924 1570788 0 60984 220236
-/+ buffers/cache: 209704 1852008
Swap: 587768 0 587768
Based on this output we grab the line with Mem and using awk pick specific fields for our computations.
This will report the percentage of memory in use
% free | grep Mem | awk '{print $3/$2 * 100.0}'
23.8171
This will report the percentage of memory that's free
% free | grep Mem | awk '{print $4/$2 * 100.0}'
76.5013
You could create an alias for this command or put this into a tiny shell script. The specific output could be tailored to your needs using formatting commands for the print statement along these lines:
free | grep Mem | awk '{ printf("free: %.4f %\n", $4/$2 * 100.0) }'
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 2 years ago.
Improve this question
What is equivalent of Linux's 'free' command on FreeBSD v8.1?
I am calling 'free' from my application and reporting the results in my application's log file. What would be the replacement when porting to FreeBSD v8.1?
Here is a sample run of 'free' on Linux:
[centos4x32 ~] free
total used free shared buffers cached
Mem: 774452 733044 41408 0 98040 328880
-/+ buffers/cache: 306124 468328
Swap: 2031608 224 2031384
vmstat has default output which is similar in nature and takes many options that give extremely detailed information, eg vmstat -m
swapinfo would cover the swap part
top -d1 causes top to print one screen and exit, and the banner is very similar to free. Use top -d1 | head -n 7 to see only the banner
Maybe freecolor command is a choice. Install it:
# cd /usr/ports/sysutils/freecolor
# make install clean
Use it:
# freecolor
Physical : [#################################..] 94% (1907820/2018396)
Swap : [###################################] 100% (1048540/1048540)
# freecolor -m -o
total used free shared buffers cached
Mem: 1971 107 1863 0 0 0
Swap: 1023 0 1023
Please refer FreeBSD find out RAM size Including Total Amount of Free and Used Memory Size.
vmstat -s gives some more human-readable or script-parseable information, including listing the page size. Otherwise, it gives output in numbef of pages. With no options, vmstat gives a brief summary.
The vmstat command also exists on NetBSD.
just use old good htop
install htop
pkg install htop
to run
htop
Other option:
# vmstat fre
procs memory page faults cpu
r b w avm fre flt re pi po fr sr in sy cs us sy id
0 0 0 13475M 24M 689 1 2 0 344 394 14693 37734 60809 7 43 50
You can use this script.
# fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
# mv freebsd-memory.pl.txt /usr/local/bin/free
# chmod +x /usr/local/bin/free
source: http://www.cyberciti.biz/faq/freebsd-command-to-get-ram-information/