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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:10:13+00:00 2026-06-13T11:10:13+00:00

How can I sync 3 different processes with signals in Unix on C/C++? I

  • 0

How can I sync 3 different processes with signals in Unix on C/C++?
I need: first process starts second process. Second process starts third process. After third process is started I want kill all processes in order 1 – 2 – 3.

I have no idea about using wait, signal, pause etc functions for this. Could you help me? Thanks.

#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

using namespace std;

int main (int argc, char * const argv[]) {

    pid_t three_pid;
    pid_t second_pid;
    pid_t first_pid;

    cout << "child 1 is started" << endl;

    pid_t pid;

    if ((pid = fork()) == -1)
    {
        cout << "fork errror" << endl;
        exit(EXIT_FAILURE);
    }
    else if (pid == 0)
    {
        second_pid = getpid();

        cout << "child 2 is started" << endl;

        pid_t pid2;

        if ((pid2 = fork()) == -1)
        {
            cout << "fork 2 error" << endl;
            exit(EXIT_FAILURE);
        }
        else if (pid2 == 0)
        {
            three_pid = getpid();
            cout << "child 3 is started" << endl;

            cout << "child 3 is TERMINATED" << endl;
        }
        else
        {
            cout << "child 2 is TERMINATED" << endl;
        }
    }
    else
    {
        first_pid = getpid();

        cout << "child 1 is TERMINATED" << endl;
    }
}
  • 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-13T11:10:14+00:00Added an answer on June 13, 2026 at 11:10 am

    To do this in a portable way let process 3 (the grandchild) call kill(<pid1>, SIGKILL) and use kill(<pid1>, 0) to test if the process is still running. If its gone kill() will fail with errno set toESRCH.

    Then let process 3 do the same for <pid2>.

    Then let process 3 terminate.

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

Sidebar

Related Questions

Developers can use Apple’s iCloud APIs to sync app data between different versions of
I need to keep my development trees in sync on different computers, with no
How can i sync sql server 2008-R2 (remopte server and local) using Microsoft Sync
I'm looking for a library to sync Twitter clients across different platforms. I've seen
I've got a problem when I try to sync files in two different repos.
For our application(desktop in .net), we want to have 2 databases in 2 different
How can I ask what commits are different between my current local branch and
I found it is hard to keep my environment variables sync on different machines.
i'm wondering how can i sync the speed (obviously, to the less fast) of
I can't seem to find much information on the web about the different approaches

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.