Handle a signal: Difference between revisions

m (→‎{{header|Sidef}}: updated code)
imported>Nmz
 
Line 1,068:
wait
</syntaxhighlight>
=={{header|Lua}}==
<syntaxhighlight lang="lua">
local start_date = os.time()
 
local loop = true
local Exit = function ()
print()
loop = false
end
 
local posix = require"posix"
posix.signal(posix.SIGINT, Exit)
posix.signal(posix.SIGQUIT, Exit)
 
local int = 0
while loop do
int = int+1
print(int)
posix.time.nanosleep{tv_sec=0,tv_nsec=500*1000*1000}
end
 
print(os.time() - start_date)
</syntaxhighlight>
{{out}}
=={{header|MATLAB}}==
MATLAB versions 6.5 (R13) and newer can no longer catch CTRL+C with a try-catch block. The onCleanup() function was introduced in version 7.6 (R2008a), possibly specifically for this situation. However, the designated onCleanup() function will execute no matter how the function ends (task completion, CTRL+C, exception), and CTRL+C will still cause an exception to be thrown and displayed.
Anonymous user