{"id":7213,"date":"2018-02-12T07:42:53","date_gmt":"2018-02-11T23:42:53","guid":{"rendered":"http:\/\/rmohan.com\/?p=7213"},"modified":"2018-02-12T07:43:14","modified_gmt":"2018-02-11T23:43:14","slug":"memory-usage-in-linux-per-process","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7213","title":{"rendered":"memory usage in Linux per process"},"content":{"rendered":"<p><em>Not because I really want to; but because I just don\u2019t have the money to spend on a 2+ GB RAM VPS and I would like to run Jira. <\/em><\/p>\n<p><em>In order to do this I keep a close eye on the processes running and how much memory each takes. <\/em><\/p>\n<p>For this I found (and tweaked) the following bash command (originally found <a href=\"http:\/\/www.linuxquestions.org\/questions\/programming-9\/how-to-show-the-top-processes-eating-ram-in-human-readable-826216\/\">here<\/a>):<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>ps -eo size,pid,user,command --sort -size | awk '{ hr=$1\/1024 ; printf(\"%13.2f Mb \",hr) } { for ( x=4 ; x&lt;=NF ; x++ ) { printf(\"%s \",$x) } print \"\" }'<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>This command will output every process and its memory usage in human readable (thus megabytes) format. For your convenience it is sorted by memory size descending (from highest to lowest).<\/p>\n<p>An example of its use:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre>test@rmohan.com:~$ ps -eo size,pid,user,command --sort -size | awk '{ hr=$1\/1024 ; printf(\"%13.2f Mb \",hr) } { for ( x=4 ; x&lt;=NF ; x++ ) { printf(\"%s \",$x) } print \"\" }'\r\n0.00 Mb COMMAND\r\n116.18 Mb \/usr\/sbin\/mysqld\r\n11.58 Mb \/usr\/sbin\/apache2 -k start\r\n11.58 Mb \/usr\/sbin\/apache2 -k start\r\n11.58 Mb \/usr\/sbin\/apache2 -k start<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>(I am sure I can tune the above to use less memory; this is merely an example)<\/p>\n<p>I hope it will be as useful to you as it is to me,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not because I really want to; but because I just don\u2019t have the money to spend on a 2+ GB RAM VPS and I would like to run Jira. <\/p>\n<p>In order to do this I keep a close eye on the processes running and how much memory each takes. <\/p>\n<p>For this I found [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7213"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7213"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7213\/revisions"}],"predecessor-version":[{"id":7215,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7213\/revisions\/7215"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}