joan2937 / pigpio

pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).
The Unlicense
1.45k stars 407 forks source link

sigHandler: Unhandled signal 2, terminating #528

Closed darshitagrawal closed 1 year ago

darshitagrawal commented 2 years ago

I am working on interfacing dht11 with Raspberry Pi. My code is as per this link: https://github.com/jimstudt/dht11-pigpio/blob/master/dht11-pigpio.c. My concern is when I press Ctrl+C, I get the error "Unhandled Signal 2, terminating" and after that I cannot write further commands on my linux terminal. Can anyone tell me what should I do?

162255367-11d24822-d49a-44cc-a042-29100eebb8a0

guymcswain commented 2 years ago

By default, pigpio sets up to handle all signals but you have to attach a function to the signal - in this case SIGINT - using gpioSetSignalFunc. Try gpioSetSignal(SIGINT, cleanup) and remove atexit(cleanup). (You may need to add exit() at the end of cleanup.)

Your other choice is the disable this default behavior and to handle the signal directly in your code.

darshitagrawal commented 2 years ago

I tried putting this in my code. But I still cannot execute further commands in my linux terminal. I can type the commands plainly but they are not being executed. What should I do?

guymcswain commented 2 years ago

Do this before you invoke gpioInitialise():

int cfg = gpioCfgGetInternals();
cfg |= PI_CFG_NOSIGHANDLER;  // (1<<10)
gpioCfgSetInternals(cfg);
guymcswain commented 2 years ago

@darshitagrawal , I have posted an improved signal handling topic branch on the repo named signals. Can you test this issue against the signals branch?

wget https://github.com/joan2937/pigpio/archive/signals.zip
unzip signals.zip
cd pigpio-signals
make
sudo make install