From: Patrick Chkoreff <pc@fexl.com>
To: The Cygwin Mailing List <cygwin@cygwin.com>
Subject: setrlimit always fails
Date: Thu, 11 Feb 2021 10:23:02 -0500 [thread overview]
Message-ID: <b0924bcb-56d0-a026-84b5-71750537facb@fexl.com> (raw)
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:
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
int main(void)
{
struct rlimit rlim;
rlim.rlim_cur = 1;
rlim.rlim_max = 1;
if (setrlimit(RLIMIT_CPU,&rlim) < 0)
{
perror("setrlimit");
exit(1);
}
printf("HEY\n");
while (1)
{
}
printf("BYE\n");
return 0;
}
$ gcc test.c
$ ./a.exe
setrlimit: Invalid argument
I have found that the only way to make the setrlimit call succeed is to
use RLIM_INFINITY:
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
But then of course it does not achieve the desired result of timing out
after 1 second.
Any ideas?
-- Patrick
next reply other threads:[~2021-02-11 15:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-11 15:23 Patrick Chkoreff [this message]
2021-02-12 2:06 ` Ken Brown
2021-02-12 7:26 ` Brian Inglis
2021-02-12 9:12 ` Corinna Vinschen
2021-02-12 18:56 ` Brian Inglis
2021-02-12 20:38 ` Brian Inglis
2021-02-12 15:11 ` Patrick Chkoreff
2021-02-15 9:14 ` Corinna Vinschen
2021-02-15 19:54 ` Patrick Chkoreff
2021-02-15 20:48 ` Corinna Vinschen
2021-02-16 14:53 ` Patrick Chkoreff
2021-02-16 15:22 ` Marco Atzeri
2021-02-16 18:33 ` Brian Inglis
2021-02-12 9:11 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b0924bcb-56d0-a026-84b5-71750537facb@fexl.com \
--to=pc@fexl.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).