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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:08:05+00:00 2026-05-23T17:08:05+00:00

I have a parent process that forks two children. I need to force a

  • 0

I have a parent process that forks two children. I need to force a certain order for when these child processes run.

For example, the parent process takes a “command” from a file, and depending on that command, the parent will either pass that command to child a or child b using unnamed pipes. I need stuff to happen in the children in the same order that the parent received the command from the file.

The way I was using semaphores did not work between processes. Any ideas?

  • 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-23T17:08:06+00:00Added an answer on May 23, 2026 at 5:08 pm

    Semaphores work just fine between processes. For example:

    #include <stdio.h>
    #include <semaphore.h>
    #include <unistd.h>
    
    int main(void)
    {
      // Error checking omitted for expository purposes
      sem_t *sem = sem_open("test_semaphore", O_CREAT|O_EXCL, 0, 1);
      sem_unlink("test_semaphore");
      int child = fork();
      printf("pid %d about to wait\n", getpid());
      sem_wait(sem);
      printf("pid %d done waiting\n", getpid());
      sleep(1);
      printf("pid %d done sleeping\n", getpid());
      sem_post(sem);
    
      if(child > 0)
      {
        int status;
        printf("parent done, waiting for child\n");
        wait(&status);
      }
    
      printf("pid %d exiting\n", getpid());
      return 0;
    }
    

    Output:

    $ time ./a.out
    pid 61414 about to wait
    pid 61414 done waiting
    pid 61415 about to wait
    pid 61414 done sleeping
    parent done, waiting for child
    pid 61415 done waiting
    pid 61415 done sleeping
    pid 61415 exiting
    pid 61414 exiting
    
    real    0m2.005s
    user    0m0.001s
    sys 0m0.003s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a process that starts several child processes. The parent needs to
I have a server application that forks several child processes. When showing the processes
i have to write program, which will create two child processes These processes would
I have this program in C++ that forks two new processes: #include <pthread.h> #include
I have created two processes using fork(). The child process is producing and writing
As part of a Linux benchmark application, I have a parent process that forks
By default in Resque the parent process forks and the children processes create a
I am currently trying to communicate a parent process which should have multiple children
I have a parent and a child process written in C language. Somewhere in
If you have Parent has_many :children Child Is there any reason a foreign key

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.