tcsetattr() crashes program

when I run my program in background (./my_app &)
it crashes on tcsetattr().

how to check ‘can I run tcsetattr()’ ?

Background or not, I don’t think it should crash. Is your program running fine without that “&” ?
Do you have a sample code to show the problem?

sory, I was wrong - the program is not terimnated - it is stopped on tcsetattr() !
why ?

ps. of course program works fine without ‘&’ :slight_smile:

“stopped”? tcsetattr() prepare a message and send it to the fd you give it.
(cvs.qnx.com/cgi-bin/cvsweb.cgi/l … web-markup)

Are you really sure it is “stopped” in “tcsetattr()” ? what is “pidin” says about your program (what status it is in while it “stopped”) ?

The reason that it is stopped has to do with the behaviour of background processes and terminal operations. If you perform a terminal operation and you are in the background, then you will be forced to into a terminal STOP state in order to allow the program to be returned to the foreground where the terminal operation can continue.

Any terminal operation performed in a background task will have this behaviour.

tfletche: You’re right - that’s it :slight_smile:

…and here is full info what’s going on:
"
According to POSIX Terminal Interface, the terminal driver should
send SIGTTIN and SIGTTOU to the process if an Background process tries
to read or write the Terminal.

Members of the foreground process group are allowed to read/write
to/from the controlling terminal.
Members of the background process groups receive SIGTTIN/SIGTTOU signals,
whose default action is to stop the process.
"

So, to prevent bkgnd process (run with ‘&’) from being stopped I should insert:

signal( SIGTTIN, SIG_IGN );
signal( SIGTTOU, SIG_IGN );

…before any printf / scanf / etc.

PS.
it works :slight_smile: