Find ulimit -a for other users

Does anyone know how to find the values ​​of "ulimit -a" for another user on Linux? I want user A to be able to check User B ulimit values. Assumptions are user A, and user B are non-root users.

Thank you in advance

+6
source share
4 answers

If I understand correctly, you want to achieve something like the following ...

Assuming I'm root, and I would like to know the soft limit information configured for the fred user, the following approach:

su - fred -c "ulimit -Sa" 

will return the desired values.

Alternatively, if, according to your question, you are not a root user, then you can use sudo and optionally enter the required password at runtime, as shown here.

 echo "freds password" | sudo -Siu fred ulimit \-Sa 
+3
source

I would suggest:

 grep 'open files' /proc/$( pgrep -o <some-user> )/limits 

For instance:

 grep 'open files' /proc/$( pgrep -o memcache )/limits 

You need to understand that pgrep -o will match the oldest of the processes; which, I suppose, is the parent.

+2
source

Pancho's answer is correct, but sometimes you may get this error:

 su - www-data -c "ulimit -n" 

No directory logged in with HOME = /

This account is currently unavailable.

You can specify a shell to overcome this:

 su www-data --shell /bin/bash --command "ulimit -aH" 

( -aH gives you a hard limit, -aS gives you a soft limit)

0
source

Choose a process for the user and define your limits:

 return-limits(){ for process in $@ ; do process_pids=`pgrep $process` if [ -z $@ ]; then echo "[no $process running]" else for pid in $process_pids; do echo "[$process #$pid -- limits]" cat /proc/$pid/limits done fi done } return-limits mongod 
0
source

Source: https://habr.com/ru/post/973805/


All Articles