gr8odinsraven
gr8odinsraven

Reputation: 143

Find ulimit -a for other users

Is anyone aware of a way to find the "ulimit -a" values for another user in Linux? I want user A to be able to check User B's ulimit values. Assumptions are the User A and User B are non-root users.

Thanks in advance

Upvotes: 13

Views: 57104

Answers (4)

Diego Castelo Branco
Diego Castelo Branco

Reputation: 11

Select a process for user and identify 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

Upvotes: 1

huynhbaoan
huynhbaoan

Reputation: 121

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

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

No directory, logging in with HOME=/

This account is currently not available.

You may specify a shell to overcome this:

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

( -aH give you hard limit, -aS give you soft limit )

Upvotes: 10

Renich
Renich

Reputation: 169

I would suggest:

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

For example:

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

You need to realize that pgrep -o will match the oldest of the processes; which, I'd presume, is be the parent.

Upvotes: 7

Pancho
Pancho

Reputation: 2193

If I am understanding correctly, you are wanting to achieve something like the following...

Assuming I am root and I would like to find out the soft limit information configured for the user fred, the following approach:

su - fred -c "ulimit -Sa"

will return the desired values.

Alternatively, if as per your question, you are not root, then you could use sudo and if desired inject the necessary password on execution as shown here

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

Upvotes: 6

Related Questions