Cannot open /dev/console

此生再无相见时 提交于 2019-12-10 05:24:44

问题


//  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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!