Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:58:48+00:00 2026-05-17T02:58:48+00:00

I am writting an application that has multiple threads in Linux environment using C

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:58:49+00:00Added an answer on May 17, 2026 at 2:58 am

    In C you handle command line arguments by having main take two arguments,

    int main(int argc, char** argv)
    

    in which argc is the number of command line arguments (including the program itself) and argv is a pointer to a memory location where argc-1 pointers to strings with the actual arguments are located. Example:

    int main(int argc, char** argv)
    {
      printf("The program was executed as %s.\n", argv[0]);
      printf("The arguments were:\n");
      for (int i = 1; i < argc; i++)
        printf("%s\n", argv[i]);
      return 0;
    }
    

    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:

    if (argc != 2)
    {
      printf("Need exactly one argument!\n");
      return 1;
    }
    int num_threads = atoi(argv[1]); // Convert first argument to integer.
    if (num_threads < 1)
    {
      printf("I'll spawn no less than 1 thread!\n");
      return 2;
    }
    

    Now what you do is simply create an array of thread handles,

    pthread_t* threads = malloc(num_threads*sizeof(pthread_t));
    

    and use it to store the thread handles as you start num_threads number of threads using pthread_create.

    If you are not familiar with pthreads at all, I recommend this short tutorial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application that has a multiple producer, single consumer model (multiple threads
I'm writing an audio application that has multiple threads producing sound and one thread
Im writing a WPF application that has a zoom and pan ability, but what
I'm writing a VB.Net WinForms application that has multiple data girds on any given
I am writting an application that autogenerated the data input UI from a java
I'm writting a small desktop application that prvides access to user's facebook account. To
Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing a Web application that has a user interface for editing data.
I'm writing a module that has multiple questions users can chose to answer. Each
I am creating an application that manages multiple instances of an external utility, supplying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.