3

I am trying to write a solution for another user, when I noticed that sudo ulimit -c returns command not found. So then I tried this:

$ sudo ulimit -c
  sudo: ulimit: command not found

$ ulimit -c
0

$ sudo -i
# ulimit -c
0

so... it works from root, and it works with out sudo, but not with sudo. Is this a bug?

j0h
  • 14,825

2 Answers2

7

ulimit is a shell built-in command like cd you can't use like:

sudo cd /test/

similarly you can't use

sudo ulimit -c

This is not a separate program. sudo looks for a binary to run, but there is no ulimit binary.

If you want to change your limit then you can define limits in limits.conf file. Those limits are defined in /etc/security/limits.conf or /etc/security/limits.d/. you can take help from this question

or

use shell like:

sudo sh -c "ulimit -c"
sudo bash -c "ulimit -c"
sudo bash -c ulimit 
sudo sh -c "ulimit -n"
pl_rock
  • 11,297
2

Is this a bug?

No. sudo has no knowledge of commands that are built in to the various shells, like ulimit and cd.

You've been presented with two ways of addressing this — using a shell as an intermediary and adjusting the limits elsewhere than on the command line itself. Here is a third, for the situations when one is trying to use such commands to make modifications to process state rather than to display it.

If one could run the shell builtins as sudo ulimit … or sudo cd … to actually modify process state, that would not be particularly useful. That would run nothing else afterwards, in the process whose limits or working directory had been changed. One would adjust process limits or working directory only to immediately exit the process.

But there are toolsets with chain-loading external commands with these functions. They do the same thing as the shell builtins but also chain load to another program after they have done so.

They are the various daemontools-family toolsets — daemontools, daemontools-encore, nosh, perp, s6, freedt, and runit.

The tools for setting limits and then chain loading to another program are variously softlimit (daemontools), softlimit (freedt), softlimit (daemontools-encore) softlimit (nosh), s6-softlimit (s6), chpst (runit), and runlimit (perp). So one could run, say, vim with an altered core file size limit using daemontools, daemontools-encore, nosh, or freedt with the command:

sudo softlimit -c 0 vim

nosh also has a similar ulimit command that uses different unit sizes for the various limits to the ones used with softlimit:

sudo ulimit -c 0 vim

The same goes for changing directory, for which there are the nosh chdir external chain-loading command:

sudo chdir /etc vim rc.local

and the cd external command from execline:

sudo /command/cd /etc vim rc.local
JdeBP
  • 3,959