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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:25:56+00:00 2026-05-21T19:25:56+00:00

(there is a follow up to this question here ) I am working on

  • 0

(there is a follow up to this question here)

I am working on trying to write a Python based Init system for Linux but I’m having an issue getting signals to my Python init script. From the ‘man 2 kill’ page:

The only signals that can be sent to process ID 1, the init process,  are  those for which init has explicitly installed signal handlers.

In my Python based Init, I have a test function and a signal handler setup to call that function:

def SigTest(SIG, FRM):
    print "Caught SIGHUP!"

signal.signal(signal.SIGHUP, SigTest)

From another TTY (the init script executes sh on another tty) if I send a signal, it is completely ignored and the text is never printed. kill -HUP 1

I found this issue because I wrote a reaping function for my Python init to reap its child processes as they die, but they all just zombied, it took awhile to figure out Python was never getting the SIGCHLD signal. Just to ensure my environment is sane, I wrote a C program to fork and have the child send PID 1 a signal and it did register.

How do I install a signal handler the system will acknowledge if signal.signal(SIG, FUNC) isn’t working?

Im going to try using ctypes to register my handler with C code and see if that works, but I rather a pure Python answer if at all possible.

Ideas?

( I’m not a programmer, Im really in over my head here :p )

Test code below…

import os
import sys
import time
import signal


def SigTest(SIG, FRM):
    print "SIGINT Caught"

print "forking for ash"
cpid = os.fork()
if cpid == 0:
    os.closerange(0, 4)
    sys.stdin = open('/dev/tty2', 'r')
    sys.stdout = open('/dev/tty2', 'w')
    sys.stderr = open('/dev/tty2', 'w')
    os.execv('/bin/ash', ('ash',))

print "ash started on tty2"

signal.signal(signal.SIGHUP, SigTest)

while True:
    time.sleep(5.0)
  • 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-21T19:25:57+00:00Added an answer on May 21, 2026 at 7:25 pm

    Signal handlers mostly work in Python. But there are some problems. One is that your handler won’t run until the interpreter re-enters it’s bytecode interpreter. if your program is blocked in a C function the signal handler is not called until it returns. You don’t show the code where you are waiting. Are you using signal.pause()?

    Another is that if you are in a system call you will get an exception after the singal handler returns. You need to wrap all system calls with a retry handler (at least on Linux).

    It’s interesting that you are writing an init replacement… That’s something like a process manager. The proctools code might interest you, since it does handle SIGCHLD.

    By the way, this code:

    import signal
    
    def SigTest(SIG, FRM):
        print "SIGINT Caught"
    
    signal.signal(signal.SIGHUP, SigTest)
    
    while True:
        signal.pause()
    

    Does work on my system.

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

Sidebar

Related Questions

As a follow up to this question: Is there an easy way to pickle
Trying to follow this example. (Section String sorting...) Is there anything obvious that would
I want to include Core Location and I'm trying to follow this tutorial: http://www.mobileorchard.com/hello-there-a-corelocation-tutorial/
This is sort of a secondary question to my question here but it was
this is a follow up on my question on paypal integration. I'm working ona
As a follow up to this question here . I am calling pgnuplot using
I am referring as a follow up on this question here: Regular expression to
This is something of a follow-up question to my question here . You can
I am trying to follow this tutorial (http://railscasts.com/episodes/88-dynamic-select-menus) to get dynamic select boxes working
Okay, so this might be kind of strange but here's the question: I have

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.