Reputation: 44325
I created a python code following this description:
import os
import time
import signal
def receiveSignal(signalNumber, frame):
print('Received:', signalNumber)
return
signal.signal(signal.SIGUSR1, receiveSignal)
# output current process id
print('My PID is:', os.getpid())
# wait in an endless loop for signals
while True:
print('Waiting...')
time.sleep(3)
which runs fine. But when I try to send a SIGUSR1
signal from another terminal, e.g. :
kill -10 55947
the python code fails as follows:
My PID is: 55947
Waiting...
Waiting...
Bus error: 10
The code is running on MacOS 10.13.6, and I tried using python 2.7.12 and python 3.6.2. In both cases I get that Bus Error
.
Is there a way to fix that? Maybe this is a mac issue? I expect the running code to execute the method receiveSignal
, but otherwise stay in the shile
loop.
Upvotes: 0
Views: 1467
Reputation: 6590
I think, the problem is, in MacOS, the SIGNAL 10
means SIGBUS
.
See the signal list https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/signal.3.html
See the signal details,
1 SIGHUP terminate process terminal line hangup
2 SIGINT terminate process interrupt program
3 SIGQUIT create core image quit program
4 SIGILL create core image illegal instruction
5 SIGTRAP create core image trace trap
6 SIGABRT create core image abort program (formerly SIGIOT)
7 SIGEMT create core image emulate instruction executed
8 SIGFPE create core image floating-point exception
9 SIGKILL terminate process kill program
10 SIGBUS create core image bus error
...
...
30 SIGUSR1 terminate process User defined signal 1
31 SIGUSR2 terminate process User defined signal 2
Hence, the error.
Try sending SIGNAL 30
, and see :)
Upvotes: 1