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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:54:24+00:00 2026-06-17T12:54:24+00:00

I am a newbie,please be gentle!I copied the code from a book: #include <sys/types.h>

  • 0

I am a newbie,please be gentle!I copied the code from a book:

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

static int alarm_fired = 0;

void ding(int sig)
{
    alarm_fired = 1;
}

int main(int argc, char* argv[])
{
    pid_t pid;

    printf("alarm application starting\n");

    pid = fork();

    switch(pid)
    {
        case -1:
            perror("fork failed");
            exit(EXIT_FAILURE);
        case 0:
            sleep(5);
            kill(getpid(), SIGALRM);
            exit(EXIT_SUCCESS);
    }
    printf("waiting for alarm to go off\n");
    (void) signal(SIGALRM, ding);

    pause();
    if (alarm_fired)
        printf("Ding!\n");

    printf("done\n");
    exit(EXIT_SUCCESS);
}

As the author had written:

ding,simulates an alarm clock.the child process wait for five
seconds before sending a SIGALRM signal to its parent.


I tried the code above,but it has no response after printing alarm application starting

waiting for alarm to go off.So I am suspecting that the code has logic error.The line kill(getpid(), SIGALRM); may be wrong.Am i right?

  • 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-17T12:54:25+00:00Added an answer on June 17, 2026 at 12:54 pm

    You are right, the line

    kill(getpid(), SIGALRM);
    

    is wrong if the child is to send a signal to it’s parent. As it is, it’s trying to send a signal to himself, as he is passing his own pid by getpid() (get process id).

    You should use getppid() (get parent process id) so you can send the message to the parent process, like this:

    kill(getppid(), SIGALRM);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm javascript newbie...please bear with me. Modified some jQuery animation code from w3c tutorial.
I'm a newbie so please be patient. I have the following code retrieving the
Please excuse my newbie Question. I'm tryin to display data from a mysql table
Newbie with a question, so please be gentle: list = [1, 2, 3, 4,
XSLT newbie question: Please fill in the blank in the C# code fragment below:
I am a complete newbie to MySql so please be gentle. Is there an
Python newbie here so please be gentle. I'm trying to convert dbf file to
I'm a big Node.js and Mongo newbie, so please be gentle. So here's my
Ok, total Cucumber newbie here so please be gentle. As a learning Ruby/Cucumber/MongoDB endeavor
Another true newbie on Ruby here, so please be gentle... I'm working with alexreisner's

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.