免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2605 | 回复: 0
打印 上一主题 下一主题

长夜漫漫,发个“提神贴“问问,linux线程信息查看的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-07-23 00:05 |只看该作者 |倒序浏览
先看一段非常“提神的代码“
9 using namespace std;
10 void * fun(void *m)
11 {
12     pthread_attr_t attr;
13     if(pthread_attr_init(&attr) != 0)
14     {
15         cout<<"init error"<<endl;
16     }
17
18     size_t stack;
19     pthread_attr_getstacksize(&attr,  &stack);为啥我这输出还是系统默认的线程栈大小就是ulimit -s得到的那个值,困惑
20     cout<<stack<<endl;

21     if(pthread_attr_destroy(&attr) != 0)
22     {
23         cout<<"destory error"<<endl;
24     }
25     return NULL;
26 }
27
28 int main(int argc, char *argv[])
29 {
30     struct rlimit rt;
31     rt.rlim_cur = 1000000;
32     setrlimit(RLIMIT_STACK, &rt);
33     pthread_attr_t attr;
34     if(pthread_attr_init(&attr) != 0)
35     {
36         cout<<"init error"<<endl;
37     }
38     pthread_t thid;
39     size_t s = 70000;
40    if(pthread_attr_setstacksize(&attr,  s)!= 0)cout<<"set stack size error"<<endl;;设置一个新的线程栈大小
41     s = 0;
42     pthread_attr_getstacksize(&attr, &s);
43     cout<<"s:"<<s<<endl;
44     int ret;
45     if((ret = pthread_create(&thid, &attr, fun, NULL))!= 0)指定了大小
46     {
47         cout<<"ret:"<<ret<<endl;
48     }
49     sleep(10);
50     getrlimit(RLIMIT_STACK, &rt);
51     cout<<rt.rlim_cur<<" "<<rt.rlim_max<<endl;
52     return 0;
53 }
   


这样的代码提神吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP