-
Notifications
You must be signed in to change notification settings - Fork 5
/
memstat
executable file
·28 lines (24 loc) · 959 Bytes
/
memstat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Copyright (C) 2017 Mats Topel, mats.topel@marine.gu.se
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version. Please see <http://www.gnu.org/licenses/>
# for more information.
#
# Usage: memstat <COMMAND [options] ...>
#
# memstat will extract the value of the RSS column corresponding to the
# PID of the <COMMAND> every second and store it in a file named
# memstat.<PID>.txt (where <PID> is excanged for the proces id).
# Run the desired command in the background
$* &
# Kill the background command if 'memstat' is killed
trap "kill ${!} 2>/dev/null; exit 3" SIGHUP SIGINT SIGQUIT SIGTERM
# Fetch the RSS output from 'ps'
while [ -e /proc/$! ];
do
ps --pid $! -o "rss,%cpu" h >> memstat.${!}.txt
sleep 60
done