- 论坛徽章:
- 0
|
本帖最后由 iw1210 于 2013-04-25 14:44 编辑
root用户有创建最多线程的权限,如何让普通用户也有这个权限?
用一个 test.c 程序测试:- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #define MAX_TEST_THREAD 3000
- void * handle(void *data)
- {
- while(1)
- sleep(1);
- }
- int main()
- {
- int i, n, r;
- pthread_t pid;
- printf("Now try to create %d threads.\n",MAX_TEST_THREAD);
- for(i=0, n=0; i<MAX_TEST_THREAD; i++)
- {
- r = pthread_create(&pid,NULL,handle,NULL);
- if(r != 0)
- {
- fprintf(stderr,"pthread_create error: %s\n", strerror(r));
- break;
- }else
- {
- n++;
- }
- }
- printf("%d threads have been created!\n", n);
- sleep(5);
- exit(0);
- }
复制代码 [oracle@localhost]$ ./test
Now try to create 3000 threads.
pthread_create error: Resource temporarily unavailable
885 threads have been created! // oracle用户创建线程有限制,不能创建3000个线程。
[oracle@localhost]$ su
Password:
[root@localhost]# ./test
Now try to create 3000 threads.
3000 threads have been created! // root用户能创建3000个线程。
[root@localhost]#
|
|