歡迎您光臨本站 註冊首頁

請教如何限制某一個用戶使用的CPU和內存資源?

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

請教如何限制某一個用戶使用的CPU和內存資源?

例如某個用戶的程序不能佔用超過50%CPU和200M內存
《解決方案》

原帖由 sy_dlj 於 2009-4-24 21:22 發表 http://linux.chinaunix.net/bbs/images/common/back.gif
例如某個用戶的程序不能佔用超過50%CPU和200M內存

這個我也想知道,系統高手提供一下經驗。
《解決方案》

這個,去看看/etc/security/limits.conf文件。
《解決方案》

原帖由 jerrywjl 於 2009-4-25 01:47 發表 http://linux.chinaunix.net/bbs/images/common/back.gif
這個,去看看/etc/security/limits.conf文件。
喝酒了還不忘上論壇灌水啊-__-||||
《解決方案》

2樓、3樓的昨晚喝酒了?

/etc/security/limits.conf
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to
#        - rtprio - max realtime priority
《解決方案》

soft 指的是當前系統生效的設置值。hard 表明系統中所能設定的最大值。soft 的限制不能比har 限制高。用 - 就表明同時設置了 soft 和 hard 的值。

core - 限制內核文件的大小
date - 最大數據大小
fsize - 最大文件大小
memlock - 最大鎖定內存地址空間
nofile - 打開文件的最大數目
rss - 最大持久設置大小
stack - 最大棧大小
cpu - 以分鐘為單位的最多 CPU 時間
noproc - 進程的最大數目
as - 地址空間限制
maxlogins - 此用戶允許登錄的最大數目

  要使 limits.conf 文件配置生效,必須要確保 pam_limits.so 文件被加入到啟動文件中。查看 /etc/pam.d/login 文件中有:
  session required /lib/security/pam_limits.so
《解決方案》

原來是利用/etc/security/limits.conf做限制,不錯。


要使 limits.conf 文件配置生效,必須要確保 pam_limits.so 文件被加入到啟動文件中。查看 /etc/pam.d/login 文件中有:
  session required /lib/security/pam_limits.so


[ 本帖最後由 diyself 於 2009-4-25 23:26 編輯 ]
《解決方案》

我對於一個進程能使用多少的cpu的實現,比較感興趣。
要是只是通過優先順序來實現,也達不到效果啊。
比如我寫一個無限循環,如果限制cpu使用率為20%,那這個進程運行后,cpu就應該20%。
這是如何做到的呢?
《解決方案》

很好,以前還真沒關注這方面的問題
《解決方案》

原帖由 emmoblin 於 2009-4-26 11:39 發表 http://linux.chinaunix.net/bbs/images/common/back.gif
我對於一個進程能使用多少的cpu的實現,比較感興趣。
要是只是通過優先順序來實現,也達不到效果啊。
比如我寫一個無限循環,如果限制cpu使用率為20%,那這個進程運行后,cpu就應該20%。
這是如何做到的呢?

這個問題值得思考,期待高手說說。

[火星人 ] 請教如何限制某一個用戶使用的CPU和內存資源?已經有246次圍觀

http://coctec.com/docs/service/show-post-23018.html