On 2021-02-11 19:06, Ken Brown via Cygwin wrote:
On 2/11/2021 10:23 AM, Patrick Chkoreff wrote:
I'm trying to use setrlimit to impose limits on various resources such
as CPU time and memory.  The call to setrlimit always fails.  I've
distilled this into the following example test.c:
[...]
     if (setrlimit(RLIMIT_CPU,&rlim) < 0)
[...]
setrlimit: Invalid argument

Cygwin's setrlimit only supports a few resources, as you can see in the source:

https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/resource.cc;h=97777e9d223466b7635b990d6c9e0bfb9e2e9a46;hb=HEAD#l201

In that case could I suggest:

        /usr/share/doc/cygwin-doc/html/cygwin-api/compatibility.html#std-susv4
        https://cygwin.com/cygwin-api/compatibility.html#std-susv4

in https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/doc/posix.xml

get/setrlimit entries should be annotated with:

        (see chapter "Implementation Notes")

and all those entries should be links to "std-notes":

        /usr/share/doc/cygwin-doc/html/cygwin-api/std-notes.html
        https://cygwin.com/cygwin-api/std-notes.html

        <ulink url="std-notes.html">(see chapter "Implementation Notes")</ulink>

in https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=winsup/doc/posix.xml

which should have an entry documenting the limitations of get/setrlimit like 
e.g.

"<para><function>getrlimit</function> resources RLIMIT_AS, RLIMIT_CPU, RLIMIT_FSIZE, RLIMIT_DATA always return rlim_cur and rlim_max as RLIM_INFINITY, so <function>setrlimit</function> returns -1 and sets EINVAL if they are lowered, or returns 0 if unchanged. <function>getrlimit</function> resource RLIMIT_NOFILE always returns rlim_cur and rlim_max as OPEN_MAX; <function>setrlimit</function> returns 0 sets EINVAL if rlim_cur > rlim_max, does not change the value if it is RLIM_INFINITY, otherwise returns the result from <function>setdtablesize</function>. <function>getrlimit</function>/<function>setrlimit</function> resources RLIMIT_CORE and RLIMIT_STACK return the current values and set the requested values.
All other resource arguments return -1 and set EINVAL.</para>"

--
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to