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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:24:31+00:00 2026-06-14T14:24:31+00:00

I want to create copies of a process using fork() in C. I cant

  • 0

I want to create copies of a process using fork() in C.
I cant figure out how to pass arguments to the copies of my process.
For example,I want to pass an integer to the process copies.

Or I what to do, if I have a loop in which I call fork() and want to pass a unique value to processes (e.g. 0…N)

for (int i = 0; i < 4; ++i) {
    fork();
    // pass a unique value to new processes.
}
  • 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-06-14T14:24:32+00:00Added an answer on June 14, 2026 at 2:24 pm

    The nice part about fork() is that each process you spawn automatically gets a copy of everything the parent has, so for example, let’s say we want to pass an int myvar to each of two child processes but I want each to have a different value from the parent process:

    int main()
    {
        int myvar = 0;
        if(fork())
            myvar = 1;
        else if(fork())
            myvar = 2;
        else
            myvar = 3;
    
        printf("I'm %d: myvar is %d\n", getpid(), myvar);
        return 0;
    }
    

    So doing this allows each process to have a “copy” of myvar with it’s own value.

    I'm 8517: myvar is 1
    I'm 8518: myvar is 2
    I'm 8521: myvar is 3
    

    If you didn’t change the value, then each fork’d process would have the same value.

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

Sidebar

Related Questions

Imagine I have an object called image, now I want to create multiply copies
I have 2 databases, Oracle and SQlite. And I want to create exact copies
I want to create thread or process that would have its own virtual address
i want create image animation , i have 50 images with png format now
I'm trying to figure out how to create a sandbox area in my new
Preface I have a need to create multiple copies of a search form (in
I want to create a multidimensional array and initialize it with copies of a
i want create multiple search where statement $where_search is a multiple condition from post
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that

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.