This commit is contained in:
Saturneric 2020-12-13 10:37:27 +08:00
parent 9a22d818b0
commit 1cae79f533
3 changed files with 76 additions and 0 deletions

12
7/pcs/env.c Normal file
View File

@ -0,0 +1,12 @@
#include <stdlib.h>
#include <stdio.h>
int main(void) {
char *pbuf = getenv("HOME");
printf("HOME: %s\n", pbuf);
pbuf = getenv("LANG");
printf("LANG: %s\n", pbuf);
return 0;
}

17
7/pcs/exit.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
void func(void) {
printf("calling func\n");
}
int main(void) {
printf("ATEXIT_MAX: %ld\n", sysconf(_SC_ATEXIT_MAX));
if(atexit(func)) {
printf("atexit error\n");
exit(-1);
}
exit(0);
}

47
7/pcs/rlimit.c Normal file
View File

@ -0,0 +1,47 @@
#include <sys/resource.h>
#include <stdio.h>
int printRLimit(int resource) {
struct rlimit rlim;
if (getrlimit(resource, &rlim) < 0) {
printf("getrlimit error\n");
return -1;
}
if(rlim.rlim_cur != RLIM_INFINITY)
printf("CUR: %lu ", rlim.rlim_cur);
else
printf("CUR: (infinity) ");
if(rlim.rlim_max != RLIM_INFINITY)
printf("MAX: %lu ", rlim.rlim_max);
else
printf("MAX: (infinity) ");
printf("\n");
return 0;
}
int main(void) {
printRLimit(RLIMIT_AS);
printRLimit(RLIMIT_CPU);
printRLimit(RLIMIT_DATA);
printRLimit(RLIMIT_FSIZE);
printRLimit(RLIMIT_STACK);
printRLimit(RLIMIT_NPROC);
printRLimit(RLIMIT_NICE);
struct rlimit rlim;
rlim.rlim_cur = 1024;
rlim.rlim_max = 1024;
if(setrlimit(RLIMIT_STACK, &rlim) < 0) {
printf("setrlimit error\n");
}
printRLimit(RLIMIT_STACK);
return 0;
}