If you want to display real-time information printk can refer https://www.cnblogs.com/ChenChangXiong/p/11357416.html
Sometimes it does not need to debug serial port using telnet ssh remote login can not be displayed when the program is started when the print run of this time needs to be redirected
Source:
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <fcntl.h> 5 #include <sys/ioctl.h> 6 #include <unistd.h> 7 8 int main(int argc, char *argv[]) 9 { 10 int tty = -1; 11 char *tty_name = NULL; 12 13 if(argc < 2) 14 { 15 printf("Miss argument \ n- " ); 16 return 0 ; . 17 } 18 is . 19 / * Get the current tty name * / 20 is tty_name = ttyname (STDOUT_FILENO); 21 is the printf ( " tty_name:% S \ n- " , tty_name); 22 is 23 is IF ( ! strcmp (the argv [ . 1 ], " ON " )) 24 { 25 / * redirected to the current console TTY * / 26 is TTY = Open (tty_name, of O_RDONLY | O_WRONLY); 27 ioctl(tty, TIOCCONS); 28 perror("ioctl TIOCCONS"); 29 } 30 else if(!strcmp(argv[1], "off")) 31 { 32 /* 恢复console */ 33 tty = open("/dev/console", O_RDONLY | O_WRONLY); 34 ioctl(tty, TIOCCONS); 35 perror("ioctl TIOCCONS"); 36 } 37 else 38 { 39 printf("error argument\n"); 40 return 0; 41 } 42 43 close(tty); 44 return 0; 45 }
Refer to the following: https://blog.csdn.net/lqxandroid2012/article/details/79165141