0

I wrote two simple programs on Eclipse- Ubuntu to test ulimit terminal command (Their binaries are attached) ++++++++++++++++++++++++++++++++ Iterator

#include<iostream>
using namespace std;
int main(){
for(long long i = 0;;i++)
cout << i << endl;
return 0;
}

++++++++++++++++++++++++++++++++ Timer

#include<iostream>
#include<time.h>
using namespace std;
clock_t start;
int main(){
start = clock();
for(long long i = 0;;i++)
cout << i << " in " << (double)(clock()-start)/(double)CLOCKS_PER_SEC << "seconds" << endl;
return 0;
}

++++++++++++++++++++++++++++++++ TESTING timer

+ulimit -t 0; '[PATH]\timer

End of output

116997 in 1.06seconds
Killed

'+ulimit -t 1; '[PATH]\timer

End of output

102501 in 0.96seconds
Killed

'+ulimit -t 2; '[PATH]\timer

End of output

[TEST 1]133073 in 1.19seconds
Killed
[TEST 2]101894 in 1seconds
Killed
[TEST 3]100950 in 0.96seconds
Killed
[TEST 4]126723 in 1.13seconds
Killed
[TEST 5 after opening a new terminal session]229302 in 2.14seconds
Killed

'+ulimit -t 5; '[PATH]\timer

End of output

**[TEST 1]219295 in 1.99seconds
Killed**
**[TEST 2 ater opening a new session]603088 in 5.47seconds
Killed**

++++++++++++++++++++++++++++++++ TESTING iterator

+ulimit -t 0; '[PATH]\iterator'

End of output

200412
Killed

+ulimit -t 1; '[PATH]\iterator'

End of output

199462
Killed

+ulimit -t 2; '[PATH]\iterator'

End of output

206111
Killed

+ulimit -t 5; '[PATH]\iterator'

End of output

244284
Killed

what do you think is the problem? It seems that a new terminal session sets a new timelimit Thanks in advance

RofaelEmil
  • 85
  • 4
  • 10

2 Answers2

0

On GNU/Linux, cpu limits can be set for all sessions in /etc/security/limits.conf config file, provided you mention pam_limits.so in your pam configuration

Stephane Rouberol
  • 4,286
  • 19
  • 18
0

That's correct. ulimit applies to descendants of the current shell, not unrelated processes.

Barmar
  • 741,623
  • 53
  • 500
  • 612