Example for signal handler?

Does anyone know where I could find an example on writing a signal handler
function? I think I may be doing something wrong in handling a SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent process that
spawned this process would not see the reason for child termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by waitpid ().

Please help.

Rex

That’s the expected behavior. What you return in exit() gets passed to
waitpid().
Markus

“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9ileet$q6q$1@inn.qnx.com

Does anyone know where I could find an example on writing a signal handler
function? I think I may be doing something wrong in handling a SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent process that
spawned this process would not see the reason for child termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by waitpid
().

Please help.

Rex

Thanks for your response. The status passed to waitpid () contains two
bytes. The MSByte is the exit status of the child process. Some of the
bits of the LSByte indicate the reason for child termination. If I do not
use my own signal handler, the status that is passed to waitpid () contains
the reason for child termination as well as the exit flag which is always
EXIT_SUCCESS. The reason in this case is SIGSEGV. I want to know how I can
write my signal handler to also set the reason for child termination so that
it is passed into the waitpid () status. Does anyone know?

Rex

“Markus Loffler” <loffler@ces.clemson.edu> wrote in message
news:9ilesi$q8m$1@inn.qnx.com

That’s the expected behavior. What you return in exit() gets passed to
waitpid().
Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9ileet$q6q$> 1@inn.qnx.com> …
Does anyone know where I could find an example on writing a signal
handler
function? I think I may be doing something wrong in handling a SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent process
that
spawned this process would not see the reason for child termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by waitpid
().

Please help.

Rex
\

You could define a termination status that indicates SIGSEGV and use the
termination status to detect this.

You could deinstall your signal handler in the signal handler and send the
signal to yourself again.

Markus

“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9in3qs$rph$1@inn.qnx.com

Thanks for your response. The status passed to waitpid () contains two
bytes. The MSByte is the exit status of the child process. Some of the
bits of the LSByte indicate the reason for child termination. If I do not
use my own signal handler, the status that is passed to waitpid ()
contains
the reason for child termination as well as the exit flag which is always
EXIT_SUCCESS. The reason in this case is SIGSEGV. I want to know how I
can
write my signal handler to also set the reason for child termination so
that
it is passed into the waitpid () status. Does anyone know?

Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9ilesi$q8m$> 1@inn.qnx.com> …
That’s the expected behavior. What you return in exit() gets passed to
waitpid().
Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9ileet$q6q$> 1@inn.qnx.com> …
Does anyone know where I could find an example on writing a signal
handler
function? I think I may be doing something wrong in handling a
SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent process
that
spawned this process would not see the reason for child termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by
waitpid
().

Please help.

Rex


\

How do I deinstall the signal handler and send the signal to myself again?

I cannot use the first suggestion because I have to work with processes that
I did not write. These processes use the default handler. My processes
have their own signal handlers. I need a consistent way to detect abnormal
termination.

Thanks.
Rex

“Markus Loffler” <loffler@ces.clemson.edu> wrote in message
news:9in7i1$tg$1@inn.qnx.com

You could define a termination status that indicates SIGSEGV and use the
termination status to detect this.

You could deinstall your signal handler in the signal handler and send the
signal to yourself again.

Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9in3qs$rph$> 1@inn.qnx.com> …
Thanks for your response. The status passed to waitpid () contains two
bytes. The MSByte is the exit status of the child process. Some of the
bits of the LSByte indicate the reason for child termination. If I do
not
use my own signal handler, the status that is passed to waitpid ()
contains
the reason for child termination as well as the exit flag which is
always
EXIT_SUCCESS. The reason in this case is SIGSEGV. I want to know how I
can
write my signal handler to also set the reason for child termination so
that
it is passed into the waitpid () status. Does anyone know?

Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9ilesi$q8m$> 1@inn.qnx.com> …
That’s the expected behavior. What you return in exit() gets passed to
waitpid().
Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9ileet$q6q$> 1@inn.qnx.com> …
Does anyone know where I could find an example on writing a signal
handler
function? I think I may be doing something wrong in handling a
SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent
process
that
spawned this process would not see the reason for child termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by
waitpid
().

Please help.

Rex




\

You deinstall it with signal(number, SIG_DFL) or signal(number, SIG_IGN)

You send a signal to yourself with kill(getpid(), number)

Markus

“Rex Lam” <Rex.Lam@igt.com> wrote in message
news:9infpj$5d4$1@inn.qnx.com

How do I deinstall the signal handler and send the signal to myself again?

I cannot use the first suggestion because I have to work with processes
that
I did not write. These processes use the default handler. My processes
have their own signal handlers. I need a consistent way to detect
abnormal
termination.

Thanks.
Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9in7i1$tg$> 1@inn.qnx.com> …
You could define a termination status that indicates SIGSEGV and use the
termination status to detect this.

You could deinstall your signal handler in the signal handler and send
the
signal to yourself again.

Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9in3qs$rph$> 1@inn.qnx.com> …
Thanks for your response. The status passed to waitpid () contains
two
bytes. The MSByte is the exit status of the child process. Some of
the
bits of the LSByte indicate the reason for child termination. If I do
not
use my own signal handler, the status that is passed to waitpid ()
contains
the reason for child termination as well as the exit flag which is
always
EXIT_SUCCESS. The reason in this case is SIGSEGV. I want to know how
I
can
write my signal handler to also set the reason for child termination
so
that
it is passed into the waitpid () status. Does anyone know?

Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9ilesi$q8m$> 1@inn.qnx.com> …
That’s the expected behavior. What you return in exit() gets passed
to
waitpid().
Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9ileet$q6q$> 1@inn.qnx.com> …
Does anyone know where I could find an example on writing a signal
handler
function? I think I may be doing something wrong in handling a
SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent
process
that
spawned this process would not see the reason for child
termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by
waitpid
().

Please help.

Rex






\

Thank you for your help.

Rex

“Markus Loffler” <loffler@ces.clemson.edu> wrote in message
news:9inr98$bnc$1@inn.qnx.com

You deinstall it with signal(number, SIG_DFL) or signal(number, SIG_IGN)

You send a signal to yourself with kill(getpid(), number)

Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9infpj$5d4$> 1@inn.qnx.com> …
How do I deinstall the signal handler and send the signal to myself
again?

I cannot use the first suggestion because I have to work with processes
that
I did not write. These processes use the default handler. My processes
have their own signal handlers. I need a consistent way to detect
abnormal
termination.

Thanks.
Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9in7i1$tg$> 1@inn.qnx.com> …
You could define a termination status that indicates SIGSEGV and use
the
termination status to detect this.

You could deinstall your signal handler in the signal handler and send
the
signal to yourself again.

Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9in3qs$rph$> 1@inn.qnx.com> …
Thanks for your response. The status passed to waitpid () contains
two
bytes. The MSByte is the exit status of the child process. Some of
the
bits of the LSByte indicate the reason for child termination. If I
do
not
use my own signal handler, the status that is passed to waitpid ()
contains
the reason for child termination as well as the exit flag which is
always
EXIT_SUCCESS. The reason in this case is SIGSEGV. I want to know
how
I
can
write my signal handler to also set the reason for child termination
so
that
it is passed into the waitpid () status. Does anyone know?

Rex

“Markus Loffler” <> loffler@ces.clemson.edu> > wrote in message
news:9ilesi$q8m$> 1@inn.qnx.com> …
That’s the expected behavior. What you return in exit() gets
passed
to
waitpid().
Markus

“Rex Lam” <> Rex.Lam@igt.com> > wrote in message
news:9ileet$q6q$> 1@inn.qnx.com> …
Does anyone know where I could find an example on writing a
signal
handler
function? I think I may be doing something wrong in handling a
SIGSEGV.
Right now, all I am doing is exit (EXIT_FAILURE). The parent
process
that
spawned this process would not see the reason for child
termination
(SIGSEGV). It only sees EXIT_FAILURE in the status returned by
waitpid
().

Please help.

Rex








\

Markus Loffler <loffler@ces.clemson.edu> wrote:

You deinstall it with signal(number, SIG_DFL) or signal(number, SIG_IGN)

You send a signal to yourself with kill(getpid(), number)

Actually, raise(number) is probably to be preferrred.

And, if you do signal(number, SIG_IGN), that will cause the signal to
be discarded – you have to go with the SIG_DFL choice.

-David


QNX Training Services
dagibbs@qnx.com