Artificial intelligent assistant

Why "No such device or address" when open /dev/tty in the first process? Given that a simple program, as following: #include <stdio.h> #include <fcntl.h> #include <unistd.h> int main(int argc, char **argv) { int fd = -1; if (access("/dev/tty", F_OK) == 0) { fd = open("/dev/tty", O_RDWR); if (fd == -1) perror("open() :"); } return 0; } compile and make it as init (the frist process invoked by kernel), then reboot, but it would get the result: open() :No such device or address How to explain this ?

`/dev/tty` is a reference to the controlling terminal for a process. But in order for it to have a controlling terminal, a real terminal has to be opened and been assigned to the process.

Perhaps instead of opening /dev/tty you should open /dev/tty0 or /dev/console or /dev/tty1

If a process does not have a controlling terminal, and it opens a tty or pty, if nothing else is using that tty as a controlling terminal already, then the process will be assigned that tty as a controlling terminal. It is also possible to open a tty and assign it as the controlling terminal with an IOCTL if the conditions are correct.

However /dev/tty is not a real tty, so these conditions don't apply to it.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 9a6ae8fc8a0dff0b092a11f131354101