Jump to content

ioctl messes up the terminal

- - - - -

  • Please log in to reply
1 reply to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
I'll admit I have no idea how ioctl works. I wrote a program to get the width and height of the terminal, going by the examples given in Advanced Programming in the Unix Environment:



#include <stdio.h>

#include <unistd.h>

#include <sys/ioctl.h>

#include <termios.h>


int main( int argc, char **argv ){

	struct winsize size;

	ioctl( 0, TIOCSWINSZ, (char *) &size );

	printf( "Rows: %u\nCols: %u\n", size.ws_row, size.ws_col );

	return 0;

}


I was using Vim to code this program, and I had Vim suspended when I compiled it. When I ran it, I got ridiculously high values (in the thousands) for both terminal dimensions, and when I started Vim again, there was a massive overload of.. something. I don't know what happened, but my terminal window was all static, and the Activity Monitor showed the memory usage of Vim as 1 GB and climbing. I had to force quit the Terminal.

How can I do this without causing a memory overload (or whatever it was)? I don't really care that much about ioctl(), mostly I just want to know how to get the correct terminal dimensions.
Programming is a journey, not a destination.

#2
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Never mind. Fixed the problem.
Programming is a journey, not a destination.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users