( , ) linuxthread libpthread.
:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char **argv){
struct rlimit resource_limit;
if(getrlimit(RLIMIT_STACK, &resource_limit) != 0){
fprintf(stderr, "Failed to get rlimit: %s\n", strerror(errno));
return 1;
}
else{
fprintf(stderr, "In parent, RLIMIT_STACK, soft-%d, hard-%d\n",
resource_limit.rlim_cur, resource_limit.rlim_max);
}
int child_status = 0;
pid_t pid = fork();
switch(pid){
case 0:
if(getrlimit(RLIMIT_STACK, &resource_limit) != 0){
fprintf(stderr, "Failed to get rlimit: %s\n", strerror(errno));
return 1;
}
else{
fprintf(stderr, "In child after fork, RLIMIT_STACK, soft-%d, hard-%d\n",
resource_limit.rlim_cur, resource_limit.rlim_max);
}
break;
case -1:
fprintf(stderr, "Fork error: %s\n", strerror(errno));
break;
default:
waitpid(pid, &child_status, 0);
break;
}
return 0;
}
-lpthread, . -lpthread, : , libpthread linuxthread, :
In parent, RLIMIT_STACK, soft-10485760, hard--1
In child after fork, RLIMIT_STACK, soft--1, hard--1
, NPTL- libpthread, :
In parent, RLIMIT_STACK, soft-10485760, hard--1
In child after fork, RLIMIT_STACK, soft-10485760, hard--1