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 1111767
In Process

The Archive Base Latest Questions

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

I’m looking to run multiple concurrent processes in a C program. The programs will

  • 0

I’m looking to run multiple concurrent processes in a C program. The programs will take arguments from the user and then execute each argument as a child process. I think that means that all I need to do is ensure that the fork() is performed by the original parent process each time, and then each of the resultant child processes will run at the same time, and not sequentially.

Am I correct in thinking this? And can anyone let me know how I might go about doing it?

  • 1 1 Answer
  • 1 View
  • 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:36:02+00:00Added an answer on May 17, 2026 at 2:36 am

    Forgive me for diverting from the matter at hand in my previous answer (by suggesting the use of threads). Since I’m going in a completely new direction here, I feel compelled to add this as a separate answer.

    Short version:

    Please make the following changes in your program:

    1. length = argc;               // in place of length = sizeof(argv);
    2. execl(argv[i],argv[i],0);    // in place of execvp(argv[i],0);
    3. #include <unistd.h>          // if you haven't already
    

    Long version:

    (1) By the variable length, I presume you want to get the total number of arguments. argv is a pointer-to-char-pointer, and as such is simply a memory address. If you print out the length in your program, you will notice it is always 4 (or whatever is the size of a memory address in your system).

    So this:

    length = sizeof(argv);
    

    Should really be this:

    length = argc;
    

    argc holds the total number of arguments passed when executing the process. For example,

    ./a.out /bin/ps /bin/ls
    

    gives: argc = 3 (and not 2, a very common pitfall)

    (2) Another issue with your program, is the execvp call.

    The prototpye for the execvp is as follows:

    int execvp(const char *file, char *const argv[]);
    

    where, argv is the list of arguments passed to the new command, very similar to the argv in your own program.

    What you use in your program is:

    execvp(argv[i],0);
    

    Suppose i=1 and argv[1] = "/bin/ls".
    What this command does is look for the /bin/ls executable & pass a NULL pointer (0) to it. This may lead to the following runtime error:

    A NULL argv[0] was passed through an exec system call.
    

    Referring to the exec man page,

    The first argument, by convention,
    should point to the filename
    associated with the file being
    executed.

    Though it is not mandatory to pass the filename again, you certainly shouldn’t pass a NULL pointer. Since you don’t want to pass any arguments, I suggest you use the following execl call, instead:

    execl(argv[i],argv[i],0);
    

    Remember that all such calls are finally converted to execve() finally & then executed, making them equivalent eventually.

    I encourage you to read more about the exec family of functions using man.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.