Get the stack size and set the stack size of thread attribute in C Last Updated : 22 Sep, 2017 Comments Improve Suggest changes 2 Likes Like Report Prerequisite : Multithreading Syntax : C // to get size of stack int pthread_attr_getstacksize(const pthread_attr_t* restrict attr, size_t* restrict stacksize); // to set size of stack int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stacksize); . pthread_attr_getstacksize() : It is use for get threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. When successfully run then it gives 0 otherwise gives any value. First argument - It takes pthread attribute. Second argument - It takes a variable and give the size of the thread attribute. pthread_attr_setstacksize() : It is use for set new threads stack size. The stacksize attribute gives the minimum stack size allocated to threads stack. When successfully run then it gives 0 otherwise if error gives any value. First argument - It takes pthread attribute. Second argument - It takes the size of new stack (In bytes) C #include <stdio.h> #include <stdlib.h> #include <pthread.h> int main() { // for takes the size of threads stack size_t stksize; // attribute declaration pthread_attr_t atr; // it gets the threads stack size and give // value in stksize variable pthread_attr_getstacksize(&atr, &stksize); // print the current threads stack size printf("Current stack size - > %d\n", stksize); // then set the new threads stack size pthread_attr_setstacksize(&atr, 320000034); pthread_attr_getstacksize(&atr, &stksize); // print the new stack size printf("New stack size-> %d\n", stksize); return 0; } Output : Current stack size - > 4196464 New stack size-> 320000034 For compile use gcc program_name.c -lpthread Create Quiz Comment D Devanshu Agarwal 2 Improve D Devanshu Agarwal 2 Improve Article Tags : Misc C Language system-programming C-Library Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like