Skip to content

setrlimit silently fails #4509

Closed
Closed

Description

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

Activity

  1. therealkenc commented on Sep 16, 2019

    @therealkenc

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions