{"id":13191,"date":"2019-04-01T07:16:17","date_gmt":"2019-04-01T07:16:17","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13191"},"modified":"2019-04-01T07:16:17","modified_gmt":"2019-04-01T07:16:17","slug":"how-to-set-limits-on-user-running-processes-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-set-limits-on-user-running-processes-in-linux\/","title":{"rendered":"How to Set Limits on User Running Processes in Linux"},"content":{"rendered":"<p>One of the Linux\u2019s beauties is that you can control almost everything about it. This gives a system administrator a great control over his system and better\u00a0utilization of the system resources.<\/p>\n<p>While some might have never thought about doing this, it is important to know that in Linux you can limit how much resource a single user may use and for how long.<\/p>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/increase-set-open-file-limits-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Increase Number of Open Files Limit in Linux<\/a><\/p>\n<p>In this short topic, we will show you how to limit the number of processes started by user and how to check the current limits and modify them.<\/p>\n<p>Before we go any further there are two things we need to point:<\/p>\n<ol>\n<li>You need root access to your system to modify the user limits<\/li>\n<li>You must be extremely careful if you plan to modify these limits<\/li>\n<\/ol>\n<p>To setup user limits, we will need to edit the following file:<\/p>\n<pre>\/etc\/security\/limits.conf\r\n<\/pre>\n<p>This file is used to apply\u00a0<strong>ulimit<\/strong>\u00a0created by the\u00a0<strong>pam_module<\/strong>.<\/p>\n<p>The file has the following syntax:<\/p>\n<pre>&lt;domain&gt; &lt;type&gt; &lt;item&gt; &lt;value&gt;<\/pre>\n<p>Here we will stop to discuss each of the options:<\/p>\n<ul>\n<li><strong>Domain<\/strong>\u00a0\u2013 this includes usernames, groups, guid ranges etc<\/li>\n<li><strong>Type<\/strong>\u00a0\u2013 soft and hard limits<\/li>\n<li><strong>Item<\/strong>\u00a0\u2013 the item that will be limited \u2013 core size, file size, \u00a0nproc etc<\/li>\n<li><strong>Value<\/strong>\u00a0\u2013 this is the value for the given limit<\/li>\n<\/ul>\n<p>A good sample for a limit is:<\/p>\n<pre>@student \u00a0 \u00a0 \u00a0 \u00a0 \u00a0hard \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 nproc \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a020<\/pre>\n<p>The above line sets a hard limit of maximum 20\u00a0processes on the\u00a0<code>\"student\"<\/code>\u00a0group.<\/p>\n<p>If you want to see the limits of a certain process has you can simply\u00a0<strong>\u201ccat\u201d<\/strong>\u00a0the limits file\u00a0like this:<\/p>\n<pre># cat \/proc\/PID\/limits\r\n<\/pre>\n<p>Where\u00a0<strong>PID<\/strong>\u00a0is the actual process ID, you can find out process id by using\u00a0<strong>ps<\/strong>\u00a0command. For more detailed explanation, read our article that says \u2013\u00a0<a href=\"https:\/\/www.tecmint.com\/monitor-linux-processes-and-set-process-limits-per-user\/\" target=\"_blank\" rel=\"noopener\">Find Running Linux Processes and Set Process Limits Per-User Level<\/a><\/p>\n<p>So here is an example:<\/p>\n<pre># cat \/proc\/2497\/limits\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre><strong>Limit<\/strong>                     <strong>Soft Limit<\/strong>           <strong>Hard Limit<\/strong>           <strong>Units<\/strong>     \r\nMax cpu time              unlimited            unlimited            seconds   \r\nMax file size             unlimited            unlimited            bytes     \r\nMax data size             unlimited            unlimited            bytes     \r\nMax stack size            8388608              unlimited            bytes     \r\nMax core file size        0                    unlimited            bytes     \r\nMax resident set          unlimited            unlimited            bytes     \r\nMax processes             32042                32042                processes \r\nMax open files            1024                 4096                 files     \r\nMax locked memory         65536                65536                bytes     \r\nMax address space         unlimited            unlimited            bytes     \r\nMax file locks            unlimited            unlimited            locks     \r\nMax pending signals       32042                32042                signals   \r\nMax msgqueue size         819200               819200               bytes     \r\nMax nice priority         0                    0                    \r\nMax realtime priority     0                    0                    \r\nMax realtime timeout      unlimited            unlimited            us   \r\n<\/pre>\n<p>All of the lines are pretty much self explanatory. However if you want to find more the settings you can input in\u00a0<strong>limits.conf<\/strong>\u00a0file, you can have a look at the manual provided\u00a0<a href=\"https:\/\/linux.die.net\/man\/5\/limits.conf\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>If you have any questions or comments, please do not hesitate to submit them in the comment section below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/set-limits-on-user-processes-using-ulimit-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the Linux\u2019s beauties is that you can control almost everything about it. This gives a system administrator a great control over his system and better\u00a0utilization of the system resources. While some might have never thought about doing this, it is important to know that in Linux you can limit how much resource a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-set-limits-on-user-running-processes-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Set Limits on User Running Processes in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13191","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13191"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13191\/revisions"}],"predecessor-version":[{"id":13192,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13191\/revisions\/13192"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}