0

Good evening.

I have a simple C++ program infinite_print.cpp that writes 400,000 lines of "abcde...xyz".

Inside another bash script, script.sh, I executed said C++ code and redirected the output to output.txt, i.e. ./infinite_print.exe > output.txt.

I tried limiting the size of output.txt created using this bash script by setting ulimit -f 10 but failed. The resulting size of output.txt was 11MB.

Stackoverflow says I am not allow to attached screenshots to my questions yet, so a screenshot from executing script.sh can be found at this link here.

I tried reading man bash and then searching for /ulimit, googling and more but still do not know what am I doing wrong...

Out of desperation I made this account and posted this question. All help is greatly appreciated :(

Edit: Where relevant, I am using Bash on a WSL (Windows Subsystem for Linux).

Source code for infinite_print.cpp:

1  #include <bits/stdc++.h>
2  using namespace std;
3
4  int limit = 400000;
5
6  int main() {
7      for (int i = 0; i < limit; ++i) {
8          cout << "abcdefghijklmnopqrstuvwxyz\n";
9      }
10 }

Source code for script.sh:

1  #!/bin/bash
2
3  printf "Current ulimit: "; ulimit -f
4
5  # Set new ulimit.
6  ulimit -f 10
7  printf "New ulimit: "; ulimit -f
8
9  g++ infinite_print.cpp -o inf.exe
10 ./inf.exe > output.txt
11
12 ls -lh output.txt
nigel
  • 138
  • 5
  • 1
    With my Linux system the unit for option -f is 1024 bytes. I do not know how it is with your system. – Cyrus Jun 27 '21 at 16:02

1 Answers1

1

The man page for bash states: Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.

Looking at the screen capture, those permissions suggest you are not running under Linux or some other Unix system. Perhaps you are running on Windows using the Linux subsystem and that Windows does not support those settings.

It certainly works here...

Bib
  • 922
  • 1
  • 5
  • 10
  • thank you for the reply! I am using Bash on a WSL indeed. Let me try it on a VM when i get home. Perhaps it is a Windows issue. – nigel Jun 28 '21 at 01:14
  • i tried it on my VM and ulimit -f does work. So it seems that my WSL is the problem. Thank you Bib! – nigel Jun 28 '21 at 12:57
  • I'm having the exact same problem: WSL2 on windows 11. How did you get WSL to increase your fsize limit? – Ben Jul 27 '22 at 17:45