User forums > General (but related to Code::Blocks)
signals and exit(0) aren't interpreted correctly
jarro_2783:
That's wierd, because it works fine.
I'm using gcc and haven't installed anything special.
If I ignore the signal in the signal handler and press ctrl c while the program is running, it actually doesn't terminate. It keeps running as though nothing happened. The funny thing though is that codeblocks thinks it stopped. It is clearly still running, the console is open and I can still type stuff in and it keeps running as usual.
It works fine in linux, but if what you say is right then it shouldn't work in windows, but it does.
mandrav:
--- Quote from: jarro_2783 on June 13, 2006, 02:09:17 pm ---That's wierd, because it works fine.
--- End quote ---
Can you post a minimal example?
thomas:
--- Quote from: jarro_2783 on June 13, 2006, 02:09:17 pm ---That's wierd, because it works fine.
[...]
It works fine in linux, but if what you say is right then it shouldn't work in windows, but it does.
--- End quote ---
Well, I have been trying to catch SIGFPE, SIGILL, and SIGSEGV before, all of these do nothing, the program crashes as if there was no handler at all.
As far as SIGINT is concerned, MSDN says:
--- Quote ---SIGINT is not supported for any Win32 application, including Windows 98/Me and Windows NT/2000/XP. When a CTRL+C interrupt occurs, Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application such as UNIX, to become multithreaded, resulting in unexpected behavior.
--- End quote ---
jarro_2783:
--- Code: ---#include <iostream>
#include <signal.h>
void sigCatch(int sig) {
signal(SIGINT, sigCatch);
std::cout << "caught signal" << std::endl;
}
int main(int argc, char *argv[])
{
int i = 0;
signal(SIGINT, sigCatch);
while (1) {
i++;
if (i == 100000000) {
std::cout << "You can't close me" << std::endl;
i = 0;
}
}
return 0;
}
--- End code ---
I need to call signal(SIGINT, sigCatch) each time a SIGINT is thrown because the signal gets reset each time. When you run this it will just keep printing "You can't close me", then when you press ctrl-c it prints "signal caught" and just keeps going. But, codeblocks thinks it has quit after the first ctrl-c.
thomas:
--- Quote from: jarro_2783 on June 15, 2006, 01:23:41 pm ---I need to call signal(SIGINT, sigCatch) each time a SIGINT is thrown because the signal gets reset each time.
--- End quote ---
That is normal System V / Linux glibc behaviour. Under BSD and Linux glibc2, the signal is not reset.
However, you were originally asking about Windows, and Windows explicitely does not support SIGINT (see above quote from MSDN).
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version