Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why prevent a file from opening as controlling terminal (with O_NOCTTY)?

Tags:

c

linux

The purpose of O_NOCTTY is documented as :

O_NOCTTY - prevent the OS from assigning the opened file as the process's controlling terminal when opening a TTY device file

Can somebody explain the intention of preventing a file as opening a controlling terminal ?

like image 637
Lunar Mushrooms Avatar asked Aug 22 '12 18:08

Lunar Mushrooms


1 Answers

Having a controlling tty means there are certain conditions where specific signals might be sent to your program in response to things happening on the tty/window where your program is running. If the program is intended to be a daemon, it's generally cleaner to make sure you don't have a controlling tty than it is to try to write code to handle all the extra conditions that you don't really care about to begin with...

like image 183
twalberg Avatar answered Oct 16 '22 07:10

twalberg