问题
// console = fopen("con", "wt"); this worked under windows
// console = fopen("/dev/console", "wt"); segmentation fault
console = fopen("/dev/tty0", "wt"); returns zero
Writing in C, using Mint Linux. I want to talk to the console regardless of redirection of stdin & stdout.
回答1:
The /dev/console
device is not necessarily available to you. For Linux that device would only show any result if you happen to look at the current virtual terminal. Also (including Linux), for most systems /dev/console
requires elevated permissions to open it, e.g., your application is running as root
. The reason for that is because some system messages are written to the system console.
For further discussion, here are a few links:
- Linux: Difference between /dev/console , /dev/tty and /dev/tty0
- 7. Terminal Special Files such as /dev/tty from Text-Terminal HOW-TO
- Understanding /dev from Linux Journal
来源:https://stackoverflow.com/questions/29444630/cannot-open-dev-console