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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:58:12+00:00 2026-05-25T18:58:12+00:00

The following is my code. Parent forks a child. Child pause until parent sends

  • 0

The following is my code. Parent forks a child. Child pause until parent sends a signal to it, then it continues running.
My question is why doesn’t child process continue
running after parent sending signal to him. Did I miss or misunderstand something?

#include<stdio.h>
#include<unistd.h>
#include<signal.h>


void 
sigusr1( int pidno )
{
  printf("Catched\n");
}

int 
main()
{
  pid_t pid;

  signal( SIGUSR1, sigusr1 );
  if( (pid = fork()) == 0 ){
    pause();
  printf("Child\n"); 
  }

  kill( pid , SIGUSR1 ); //parent sends signal to child 
  pause();
}
  • 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-25T18:58:13+00:00Added an answer on May 25, 2026 at 6:58 pm

    Here’s what happens in the parent:

    1. Fork a child.
    2. Send SIGUSR1 to the child.
    3. Wait for a signal.

    Here’s what happens in the child:

    1. Wait for a signal.
    2. Print Child.
    3. Call kill(0, SIGUSR1) (0 being the value of pid in the child). Calling kill with a process ID of 0 sends the signal to every process in the process group of the process that calls kill.
    4. Wait for a signal.

    There are several possible behaviors for your program, depending on the order in which the parent and the child system calls are executed. Depending on the exact version of your operating system, on the fine-tuning of various kernel parameters, on how loaded your system is, and on random chance, you may or may not observe different behavior if you run the program several times or under a debugger.

    If the parent starts faster than the child, you may see this:

    1. Parent sends SIGUSR1 to the child.
    2. Child receives SIGUSR1 and prints Catched.
    3. Child calls pause.
    4. Parent calls pause.

    With this execution order, both the parent and the child end up waiting forever (it’s a deadlock).

    If the child starts faster than the parent, you may see this:

    1. Child calls pause.
    2. Parent sends SIGUSR1 to the child.
    3. Parent calls pause.
    4. Child is unblocked and prints Catched.
    5. Child prints Child.
    6. Child sends SIGUSR1 to the process group.
    7. Child prints Catched.
    8. Child calls pause.
    9. Parent is unblocked and prints Catched.
    10. Parent exits.

    I don’t think there’s a way for the child to exit: it calls pause twice, and while it can receive up to two signals, one of these is sent from itself (the one from kill(0,SIGUSR1)) and that one is delivered synchronously, not during the execution of pause.

    This program is probably not what you meant to write, but since you don’t describe the expected behavior, it’s impossible to tell what you did mean to write. I do note that you do not follow the usual structure of a program that forks:

    pid = fork();
    if (pid < 0) {
        /*error handling*/
    } else if (pid == 0) {
        /*child code*/
        exit(...); /*Usually, what follows the if is specific to the parent.*/
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a parent form A, there's the following code to call a child form
The following code sends messages from child processes to their parents using socket pairs.
Say I have the following code: class Parent { static string MyField = ParentField;
I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
If I fork a child process, and the child process exits before the parent
Running the following code resulting in an HostException; Public Sub RunPowershellInConsole(ByVal scriptText As String)
Im trying to debug the following code using System; public class Parent { string

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.