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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:49:55+00:00 2026-06-13T10:49:55+00:00

I read about add signal() function in the signal handler function can over write

  • 0

I read about add signal() function in the signal handler function can over write the default behaviour:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void signalHandler();
int main(void) {
    signal(SIGUSR1, signalHandler);
    sleep(60);
    printf("I wake up");
    return 0;
}
void signalHandler() {
    signal(SIGUSR1, signalHandler);// I add this line to overwrite the default behaviour 
    printf("I received the signal");
}

And I trigger it with another process

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {

    kill(5061, SIGUSR1); // 5061 is the receiver pid, kill(argv[1], SIGUSR1) doesn't working, when I get 5061 as parameter
    puts("send the signal ");
    return 0;
}

The receiver process wake up as soon as it receiver the SIGUSR1 signal. How can I make the receiver continue sleep even when it receive the signal from other process?

BTW why kill(5061, SIGUSR1); 5061 is the receiver pid, kill(argv[1], SIGUSR1) doesn’t work, when I get 5061 as parameter?

  • 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-13T10:49:56+00:00Added an answer on June 13, 2026 at 10:49 am

    Your question (why kill(argv[1], SIGUSR1) does not work) actually is not related to signals, but to basic C programming. Please compile with gcc -Wall -g (i.e. all warnings and debugging information) on Linux, and improve your code till no warning is given.

    Please read carefully the kill(2) man page (on Linux, after installing packages like manpages and manpages-dev and man-db on Ubuntu or Debian, you can type man 2 kill to read it on your computer). Read also carefully signal(2) and signal(7) man pages. Read these man pages several times.

    Then, understand that the kill syscall is declared as

    int kill(pid_t pid, int sig);
    

    and since pid_t is some integral type, you need to convert argv[1] (which is a string, i.e. a char*) to some integer (and kill(argv[1], SIGUSR1) should not even compile without errors, since argv[1] is not some integer but a string). So please use:

    kill((pid_t) atoi(argv[1]), SIGUSR1);
    

    The man page says also that you should use signal(SIGUSR1, SIG_DFL) to restore the default behavior, and signal(SIGUSR1, SIG_IGN) to ignore that signal.

    Of course, you should better use sigaction(2) as the man page of signal(2) tells you.

    At last, please take the habit of reading man pages and spend hours to read good books like Advanced Linux Programming and Advanced Unix Programming. They explain things much better than we can explain in a few minutes. If you are not familiar with C programming, read also some good book on it.

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

Sidebar

Related Questions

How can I add information about read article on my site to facebook RECENT
I read about using <context:component-scan base-package=tld.mydomain.business> <context:include-filter type=annotation expression=org.springframework.stereotype.Service/> </context:component-scan> and annotate my service
I read about ContactsContract.CommonDataKinds.GroupMembership , but I can't figure out what URI use to
Recently, I decided to add 4 languages to my application. I read about how
I've read about a dozen similar questions on here and tried everything I can
I'm writing a webcam app and I need to write and read about 15
How can I target dynamically loaded content with jQuery? I've read about it a
I have read about using :remote=>true in rails3 and know that it add data-remote=true
I created App which add infomation about read articles in my site to timetable.
I have System.Collections.Generic.List _myList and many threads can read from it or add items

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.