exit()

I have a problem with exit().

I have 2 process, processA and processB.
processA spwans processB.
i have a signal handler for SIGCHLD signal in processA.
To test the handler, i just inserted an exit(1) in processB.
The processes are running on pentium board, can be monitored through
serial port.(hyperterminal software)

i saw that signal handler is getting invoked through debug printf.But CPU
hangs after few comands at the hyperterminal.

After processB exits, we typed few commands like sin, ls, ps etc. But CPU
hanged after few command execution with a SIGSEV fault like /bin
terminated…SIGSEv… etc

Is it an exit issue or usage of exit in thr program.

I read in some technical article that whenever a child wanted to exit, use
_exit instead os exit??

we don’t understand?

radha krishnan wrote:

I have a problem with exit().

I have 2 process, processA and processB.
processA spwans processB.
i have a signal handler for SIGCHLD signal in processA.
To test the handler, i just inserted an exit(1) in processB.
The processes are running on pentium board, can be monitored through
serial port.(hyperterminal software)

i saw that signal handler is getting invoked through debug printf.But CPU
hangs after few comands at the hyperterminal.

If you are using printf inside signal handler your code is illegal.
printf() is not signal safe. You code could be caught in some loop
while trying to exit using all the CPU.

Process A should call wait() or waitpid() otherwise processB will stay
in zombie state (depending how it’s started)

Make sure the shell running the serial port is high priority.

After processB exits, we typed few commands like sin, ls, ps etc. But CPU
hanged after few command execution with a SIGSEV fault like /bin
terminated…SIGSEv… etc

Is it an exit issue or usage of exit in thr program.

I don’t beleive it’s related to exit. It is probably because your
program left some piece of hardware in an unknown state

I read in some technical article that whenever a child wanted to
exit, use
_exit instead os exit??

AFAIK _exit is the same as exit expect that it’s not calling functions
registered with atexit().

we don’t understand?

Mario Charest wrote:

AFAIK _exit is the same as exit expect that it’s not calling functions
registered with atexit().

No, _exit() is signal-safe. And unlike exit(), _exit() does not flush
FILE buffers (that’s why it can be signal-safe).

“Wojtek Lerch” <Wojtek_L@yahoo.ca> wrote in message
news:ci7f4h$30j$1@inn.qnx.com

Mario Charest wrote:
AFAIK _exit is the same as exit expect that it’s not calling functions
registered with atexit().

No, _exit() is signal-safe.

Ok. just check the doc and I missed that one.

And unlike exit(), _exit() does not flush FILE buffers (that’s why it
can be signal-safe).

Doc says it closes fd. I assume it meant flushing them as well. Thanks for
pointing it out.

Mario Charest wrote:

“Wojtek Lerch” <> Wojtek_L@yahoo.ca> > wrote in message
And unlike exit(), _exit() does not flush FILE buffers (that’s why it
can be signal-safe).

Doc says it closes fd. I assume it meant flushing them as well. Thanks for
pointing it out.

_exit() just asks the OS to terminate the process. When a process
terminates for any reason, the OS closes its fds; but the OS knows
nothing about any buffered data that the stdio library, or any other
library, may keep in its data structures. The OS basically knows how to
do close(fileno(fp)) for you, but that’s not quite the same as fclose(fp).

radha krishnan wrote:

I have a problem with exit().

I have 2 process, processA and processB.
processA spwans processB.
i have a signal handler for SIGCHLD signal in processA.
To test the handler, i just inserted an exit(1) in processB.
The processes are running on pentium board, can be monitored through
serial port.(hyperterminal software)

i saw that signal handler is getting invoked through debug printf.But CPU
hangs after few comands at the hyperterminal.

After processB exits, we typed few commands like sin, ls, ps etc. But CPU
hanged after few command execution with a SIGSEV fault like /bin
terminated…SIGSEv… etc

Is it an exit issue or usage of exit in thr program.

I read in some technical article that whenever a child wanted to exit, use
_exit instead os exit??

we don’t understand?

Thanks.

I found the reason behind this hang. This was because , the exit unlinked
the shared memory, which was being used by arcnet driver.