Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setrlimit silently fails #4509

Closed
smasher164 opened this issue Sep 16, 2019 · 1 comment
Closed

setrlimit silently fails #4509

smasher164 opened this issue Sep 16, 2019 · 1 comment

Comments

@smasher164
Copy link
Member

Windows build number:

>ver

Microsoft Windows [Version 10.0.18362.295]

What I'm doing and what's happening:

Use any C compiler to produce binaries for WSL and any POSIX for the following source file:

#include <errno.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
  struct rlimit rlp = {1, 4};
  if (setrlimit(RLIMIT_NPROC, &rlp) < 0) goto handle;

  rlp.rlim_cur = 0;
  rlp.rlim_max = 0;
  if (getrlimit(RLIMIT_NPROC, &rlp) < 0) goto handle;
  printf("Process limits: (%llu, %llu)\n", rlp.rlim_cur, rlp.rlim_max);

  if (fork() < 0) goto handle;
  printf("Hello 1\n");
  if (fork() < 0) goto handle;
  printf("Hello 2\n");
  if (fork() < 0) goto handle;
  printf("Hello 3\n");

  return 0;
handle:
  perror(NULL);
  return 1;
}

What's wrong / what should be happening instead:

The outputs on the two systems differ. Here is the correct output produced on my Ubuntu system:

$ ./a.out
Process limits: (1, 4)
Resource temporarily unavailable

And here is the output from WSL(Ubuntu):

$ ./a.out
Process limits: (1, 4)
Hello 1
Hello 1
Hello 2
Hello 2
Hello 2
Hello 2
Hello 3
Hello 3
Hello 3
Hello 3
Hello 3
Hello 3
Hello 3
Hello 3

setrlimit returns 0 to indicate success, even though the hard process limit isn't being set, which permits all of the forks to successfully execute.

Strace of the command here

@therealkenc
Copy link
Collaborator

Spiritually similar to #3505. setrlimit(2) on WSL1 is.... limited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants