Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open /dev/console

Tags:

c

linux-mint

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

like image 813
Chuck Pergiel Avatar asked Nov 09 '22 16:11

Chuck Pergiel


1 Answers

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
like image 65
Thomas Dickey Avatar answered Nov 14 '22 21:11

Thomas Dickey