I am writting an application that has multiple threads in Linux environment using C or python. I am using pthread for that. But How number of threads should be accepted via command line.
I am writting an application that has multiple threads in Linux environment using C
Share
In C you handle command line arguments by having
maintake two arguments,in which
argcis the number of command line arguments (including the program itself) andargvis a pointer to a memory location whereargc-1pointers to strings with the actual arguments are located. Example:Let’s now assume that your program takes a single command line argument, an integer telling you how many threads to spawn. The integer is given as a string, so we have to convert it using
atoi:Now what you do is simply create an array of thread handles,
and use it to store the thread handles as you start
num_threadsnumber of threads usingpthread_create.If you are not familiar with pthreads at all, I recommend this short tutorial.