ulimit -t Linux

时间:2012-08-24 09:45:56

标签: linux ulimit

我在Eclipse-Ubuntu上编写了两个简单的程序来测试ulimit终端命令(附加了他们的二进制文件) ++++++++++++++++++++++++++++++++ 迭代器

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

++++++++++++++++++++++++++++++++ 计时器

#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;
}

++++++++++++++++++++++++++++++++ 测试计时器

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

输出结束

116997 in 1.06seconds
Killed

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

输出结束

102501 in 0.96seconds
Killed

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

输出结束

[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

输出结束

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

++++++++++++++++++++++++++++++++ 测试迭代器

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

输出结束

200412
Killed

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

输出结束

199462
Killed

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

输出结束

206111
Killed

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

输出结束

244284
Killed
你觉得这个问题怎么样? 似乎新的终端会话设置了新的时间限制 提前致谢

2 个答案:

答案 0 :(得分:0)

在GNU / Linux上,可以为/etc/security/limits.conf配置文件中的所有会话设置cpu限制,前提是在pam配置中提及pam_limits.so

答案 1 :(得分:0)

这是对的。 ulimit适用于当前shell的后代,而不是不相关的进程。