리눅스 C언어 프로그램 종료후 커널 stdout에 자료 남는것 지우는방법좀알려주세요 ㅠ

soseazi의 이미지

#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
/* file descriptor for standard input */
#define STDIN 0
 
int main(int argc, char *argv[ ])
 
{	
   	struct timeval tval;	
    	fd_set readfds;	
    	tval.tv_sec = 5;	
  	tval.tv_usec = 800000;
	struct termios initial_settings, new_settings;
	FILE *input;
	FILE *output;
	input = fopen("/dev/tty", "r");
	output = fopen("/dev/tty", "w");
	if(!input || !output)
	{
		fprintf(stderr,"unable to open /dev/tty\n");
		exit(1);
	}
	tcgetattr(0, &initial_settings);
	new_settings = initial_settings;
	new_settings.c_lflag &= ~ICANON;
	new_settings.c_cc[VMIN] = 5;
	new_settings.c_cc[VTIME] = 0;
	if(tcsetattr(0, TCSANOW, &new_settings) !=0)
		fprintf(stderr,"could not set attributes\n");		
 
    	FD_ZERO(&readfds);	
    	FD_SET(STDIN, &readfds);	
    	/* don’t care about writefds and exceptfds: */	
    	select(STDIN+1, &readfds, NULL, NULL, &tval);	
    	if (FD_ISSET(STDIN, &readfds))		
		printf("\nA key was pressed lor!\n");	
    	else		
		printf("Timed out lor!...\n");
 
	tcsetattr(fileno(input),TCSANOW,&initial_settings);
	fflush(stdout);
	fflush(stdin);
    return 0;
 
}

대충 소스는 이렇습니다.

그냥 소켓프로그래밍하면서 select를 배우는과정에 조금 지져분하게 되어서 고치려고하는데요

프로그램을 실행을한다음에 5개의 문자를입력하게되면 noncanonical 모드이기에 바로 입력이되면서 그냥 프로그램이 종료가되는데요

종료가 되면 커널 입력창에 입력된 5개문자가 고스란히 나오게 되어서 이것좀 없애고싶어서요

그래서 fflush로하는건지 아니면 system("clear")로도해봐도안되고

터미널을 사용해서 하는건지 영모르겠어서요 ㅠ

./select 로 실행한후
입력하세요 : abcde 입력하면
프로그램종료

root@root:abcde

이렇게 됩니다 해결방법좀알려주세요 ㅠ

kgcrom의 이미지

어디가 문제인지는 제딴에는 알수없지만,
우선 파일 오픈 한것은 닫아 주셔야 돼요~~ : )

흘러가고있는 지금 이 시간에 충실하자.

soseazi의 이미지

터미널열고 저거 컴파일해서 abcde 입력하면

프로그램 종료후

다음 터미널 입력 부분에 고스란히 abcde가 남아서 옵니다

요게 문제 ㅠ

hoppang의 이미지

new_settings.c_lflag &= ~ECHO;

이것도 넣어보세요.
========================
http://kldp.net/projects/mimic

soseazi의 이미지

이것은 입력되는 글씨를 안보이게 하는거로 알고있습니다;ㅠ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.