473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

windows hates signal?

I am interested in digging the include directory of my favorite gcc
compiler specialized for windows(yes u get it, I use Dev-C++, but I
love c and type commands in the console).But when I find signal.h and
try it, I meet some problems.My code is:

/*signal-win.c*/
#include <stdio.h>
#include <signal.h>
#include <windows.h>

#define SIGCUST 80

void ctrlc()
{
printf("no u can not kill me\n");
signal(SIGINT, ctrlc);
}

void chandler()
{
printf("SIGCUST caught!\n");
signal(SIGCUST, chandler);
}

int main()
{
int i;

signal(SIGINT, ctrlc);
signal(SIGCUST, chandler);
while(1)
{
printf("executing...\n");
raise(SIGCUST);
Sleep(1000);
}
return 0;
}

I included windows.h bcz I want to use Sleep() function.
When I run the binary code after 'gcc -o sig.exe signal-win.c', it
outputs only 'executing..' and 'no u can not kill me' when I type
ctrl-c, where is 'SIGCUST caught!'?Does it really like somebody
described 'windows fails to be a modern O.S. after it fails in
implementing the signal mechanism' or it is just my fault?
my gcc version is 3.4.2 (mingw-special)
Thanks:)

Feb 10 '06 #1
8 7551
hlinzhou wrote:
I am interested in digging the include directory of my favorite gcc
compiler specialized for windows(yes u get it, I use Dev-C++, but I
love c and type commands in the console).But when I find signal.h and
try it, I meet some problems.My code is:

/*signal-win.c*/
#include <stdio.h>
#include <signal.h>
#include <windows.h>

#define SIGCUST 80


signals are system defined. You can't define your own signals,
only install handlers/ignore the signals provided by the system.

Also - signal and raise return values. If you checked that for errors,
you might have realized you couldn't install or raise your SIGCUST
(unless 80 happened to be also the nr of a system defined signal..)
Feb 10 '06 #2
"hlinzhou" <zh**********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I am interested in digging the include directory of my favorite gcc
compiler specialized for windows(yes u get it, I use Dev-C++, but I
love c and type commands in the console).But when I find signal.h and
try it, I meet some problems.My code is:

/*signal-win.c*/
#include <stdio.h>
#include <signal.h>
#include <windows.h>

#define SIGCUST 80

void ctrlc()
{
printf("no u can not kill me\n");
signal(SIGINT, ctrlc);
}

void chandler()
{
printf("SIGCUST caught!\n");
signal(SIGCUST, chandler);
}

int main()
{
int i;

signal(SIGINT, ctrlc);
signal(SIGCUST, chandler);
Yes, maybe this is not a comp.lang.c question but:

void (*i)(int);
if ((i=signal(SIGCUST, chandler))==SIG_ERR)
printf("Signal handler not set\n");
That could be informative. Also open your "signal.h" file, it is
enlightening.
while(1)
{
printf("executing...\n");
raise(SIGCUST);
Maybe this does not return with zero.
Sleep(1000);
}
return 0;
}

Feb 10 '06 #3
In article <11**********************@o13g2000cwo.googlegroups .com>,
hlinzhou <zh**********@gmail.com> wrote:
void ctrlc()
{
printf("no u can not kill me\n");
signal(SIGINT, ctrlc);
} void chandler()
{
printf("SIGCUST caught!\n");
signal(SIGCUST, chandler);
}

int main()
{
int i;

signal(SIGINT, ctrlc);
signal(SIGCUST, chandler);


You cannot use printf() inside a signal handler. In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.
Any I/O operations are off-limit, as is setting any other kind of
variable. Exception: if you trigger the signal yourself using
abort() or raise() then you are permitted other [unspecified] freedoms.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Feb 10 '06 #4
Walter Roberson said:
You cannot use printf() inside a signal handler.
Right, in the same way that you can't use a hockey stick in a football game.
(In other words, you /can/, but if you do, Something Bad might happen.
In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.


longjmp (sorry to pick a spelling nit, but spelling matters when using
standard library functions).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Feb 10 '06 #5
On 2006-02-10, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
In article <11**********************@o13g2000cwo.googlegroups .com>,
hlinzhou <zh**********@gmail.com> wrote:
void ctrlc()
{
printf("no u can not kill me\n");
signal(SIGINT, ctrlc);
}
void chandler()
{
printf("SIGCUST caught!\n");
signal(SIGCUST, chandler);
}

int main()
{
int i;

signal(SIGINT, ctrlc);
signal(SIGCUST, chandler);


You cannot use printf() inside a signal handler. In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.


Hold on - you can use WHAT, now? I'd never heard about longjmp being
anything like "safe" within a signal handler.
Any I/O operations are off-limit, as is setting any other kind of
variable. Exception: if you trigger the signal yourself using
abort() or raise() then you are permitted other [unspecified] freedoms.

Feb 10 '06 #6
In article <sl**********************@random.yi.org>,
Jordan Abel <ra*******@gmail.com> wrote:
On 2006-02-10, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
You cannot use printf() inside a signal handler. In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.

Hold on - you can use WHAT, now? I'd never heard about longjmp being
anything like "safe" within a signal handler.


Last time around, I overstated what could be done inside a handler,
so this time I looked it up in the official C89 standard and
listed the things it said there. I wasn't going from memory
this time around. But my C89 is at work so I can't quote exact
wording at the moment.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Feb 11 '06 #7
* Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:
Jordan Abel <ra*******@gmail.com> wrote:
On 2006-02-10, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:

You cannot use printf() inside a signal handler. In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.

Hold on - you can use WHAT, now? I'd never heard about longjmp being
anything like "safe" within a signal handler.


Last time around, I overstated what could be done inside a handler,
so this time I looked it up in the official C89 standard and
listed the things it said there. I wasn't going from memory
this time around. But my C89 is at work so I can't quote exact
wording at the moment.


As I read the C99 standard, you can use abort(), _Exit() and
signal(). The latter with limitations.

I don't have the C89 standard though.
Stefan Krah

--
Break original Enigma messages: http://www.bytereef.org/m4_project.html
Feb 11 '06 #8

In article <sl**********************@random.yi.org>, Jordan Abel <ra*******@gmail.com> writes:
On 2006-02-10, Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:

You cannot use printf() inside a signal handler. In a signal
handler, you can set variables of type volatile sig_atomic_t
and you can re-set the signal handler for the signal you are
servicing, and you can use return, exit, abort, and longjump.


Hold on - you can use WHAT, now? I'd never heard about longjmp being
anything like "safe" within a signal handler.


I don't believe "safe" is defined by the standard, though it is used
in a number of places. However:

ISO 9899-1990 7.6.2.1 (The longjmp function):

As it bypasses the usual function call and return mechanisms, the
longjmp function shall execute correctly in contexts of interrupts,
signals and any of their associated functions. However, if the
longjmp function is invoked from a nested signal handler (that is,
from a function invoked as a result of a signal raised during the
handling of another signal), the behavior is undefined.

7.7.1.1 (The signal function):

The function func may terminate by executing a return statement or
by calling the abort, exit, or longjmp function.

So within various restrictions, C90 does endorse calling longjmp from
a signal handler.

C99, however, removes this endorsement; there is no corresponding
language in the descriptions of the two functions. (See 7.13 and
7.14 in 9899-1999, either the original or n1124.)
--
Michael Wojcik mi************@microfocus.com

I would never understand our engineer. But is there anything in this world
that *isn't* made out of words? -- Tawada Yoko (trans. Margaret Mitsutani)
Feb 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Randy Yates | last post by:
Can't get the postgres server started under Win2000/cygwin. Here's what happens: $ initdb -D /Gauss/rr/data -W The files belonging to this database system will be owned by user "yates". This...
1
by: rodmc | last post by:
Hello, I am trying to figure out how to write a windows service, I am totally new to it. I have written a simple test case, however it doesn't appear to do anything. Although it installs and...
1
by: Vlad Dogaru | last post by:
Hello, I've written a simple, standalone wiki server in Python. It runs a BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is caught, at which point it writes changes to a file...
3
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
1
by: Nick ! | last post by:
Chris Share <usenet at caesium.me.ukwrote: http://web.cs.mun.ca/~rod/ncurses/ncurses.html#xterm says "The ncurses library does not catch signal, because it cannot in general know how you want...
2
by: responsible | last post by:
Hi, I am trying to convert a small piece of source code that was initially written for Linux to build under Windows. My main problem though is in two lines... 1. signal(SIGALRM,...
3
by: worlman385 | last post by:
The prototype of GetExitCodeThread is like this - GetExitCodeThread( __in HANDLE hThread, __out LPDWORD lpExitCode ); ============================= why we put &dwExitCod in the parameter?...
8
by: jadamwil | last post by:
Hello, I am using the numpy fromfile function to read binary data from a file on disk. The problem is that the program runs fine on a Mac, but gives an error or warning on windows when trying to...
4
by: Propad | last post by:
Hello, I know this issue pops up once in a while, but I haven't found a good answer to it. I need to debug a long running application under windows. The application is a combined java/python...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.