Find the answer to your Linux question:
Results 1 to 2 of 2
hi I have been reading the Linux Device Drivers 3 book. In Chapter 4 on debugging an example program for changing console for printk was given. but it is not ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    5

    usage of ioctl command TIOCLINUX


    hi I have been reading the Linux Device Drivers 3 book.

    In Chapter 4 on debugging an example program for changing console for printk was given.
    but it is not executing in my terminal what could be the reason? I have given the source code also.
    Also when I googled for the TIOCLINUX command I was able find only 10 subcommands for it. what is the subcommand 11 doing in the code? Please direct me to any article or links or guide me.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <unistd.h>
    #include <sys/ioctl.h>

    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);
    }


    Thank you

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    416
    You're getting into grotty territory there. You're not supposed to use TIOCLINUX because it's not portable, at all. But it is fun when you're banging on your linux box and getting your program to work just the way you want it to.

    I'm not going to do a bunch of research here or anything, but I do recall that TIOCLINUX varies incredibly, takes strange arguments, does strange things, and returns weirdness.

    Be careful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •