Reputation: 158
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
Upvotes: 0
Views: 679
Reputation: 977
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...
Upvotes: 1