lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 26.12.2012 16:34, Bernd Eggink wrote:

I wonder if signal handling (as in luaposix) is supposed to work in any
situation. Or are there limitations, preconditions etc.(on Linux)?

I'm asking because I have a program where signal() simply doesn't work.
After putting

     local P = require "posix"
     P.signal(P.SIGUSR1, function() print("signal") end)

at the beginning of the program, I expect the command "kill -s USR1
$pid" to print "signal", but instead the program exits immediately. This
even happens when the signal handling function is completely empty.

The program in question is pretty complex. However, in simple test
programs signal() works as expected.

Thanks for your replies.
I investigated a bit further. As my program uses a kind of UI whose event loop is essentially driven by io.read() results, I tried the following little program:

-----------------------------
local P = require "posix"

P.signal(P.SIGUSR1, function(s)
    print("Got signal", s)
end)

print(P.getpid("pid"))
os.execute("stty -echo cbreak")		-- [1]
while true do print(io.read()) end
-----------------------------

Here the signal handling works, but the output is:

Got signal      10
nil     Interrupted system call 4

Interestingly, the "Interrupted system call" disappears if the line marked [1] is commented out. OTOH, if I comment out the stty command in the original program, the signal still isn't caught, so this may be a red herring.

Regards,
Bernd