Redirect console messages

Linux on the console allows some flexibility in the recording strategy, which allows you to send messages to a specific virtual console (console if you are using a text screen). By default, the "console" is the current virtual terminal in order to select a different virtual terminal to receive a message, you may be the following program, setconsole, which console can be used to select any message received kernel calls console device ioctl (TIOCLINUX);. it must be run by the superuser may obtained from the misc-progs directory.

 

Below is a procedure should be used for a parameter to specify the number of messages received by the console.

 

int main(int argc, char **argv)

{

char bytes[2] = {11,0}; /* 11 is the TIOCLINUX cmd number */  if (argc==2) bytes[1] = atoi(argv[1]); /* the chosen console */ else {

 

fprintf(stderr, "%s: need a single arg\n",argv[0]); exit(1); } if (ioctl(STDIN_FILENO, TIOCLINUX, bytes)<0) { /* use stdin */

fprintf(stderr,"%s: ioctl(stdin, TIOCLINUX): %s\n", argv[0], strerror(errno));

exit(1);

}

exit(0);

}

 

setconsole the TIOCLINUX using special ioctl command, to implement the functions specific to the linux. using the TIOCLINUX, you pass it a pointer to the byte array as a parameter. The first number is a byte array, specify the required subcommand, the following bytes are for Laid subcommands in setconsole, the use of 11 sub-command, the next byte (stored in bytes [1]) specify the virtual console. TIOCLINUX complete description of the source code kernel drivers / char / tty_io .c years.

 

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11106353.html