diff --git a/7/pcs/env.c b/7/pcs/env.c new file mode 100644 index 0000000..faaf6a7 --- /dev/null +++ b/7/pcs/env.c @@ -0,0 +1,12 @@ +#include +#include + +int main(void) { + char *pbuf = getenv("HOME"); + printf("HOME: %s\n", pbuf); + + pbuf = getenv("LANG"); + printf("LANG: %s\n", pbuf); + + return 0; +} diff --git a/7/pcs/exit.c b/7/pcs/exit.c new file mode 100644 index 0000000..ac05bf9 --- /dev/null +++ b/7/pcs/exit.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +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); +} diff --git a/7/pcs/rlimit.c b/7/pcs/rlimit.c new file mode 100644 index 0000000..710a91e --- /dev/null +++ b/7/pcs/rlimit.c @@ -0,0 +1,47 @@ +#include +#include + +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; +}