시스템 프로 그래 밍 인원 은 파이프 프로 그래 밍 을 배 워 야 한다.

로스앤젤레스 대학의 cs 635 과정 을 볼 때 간단 한 프로그램 이 있 습 니 다. Liux 의 cat 명령 을 모방 한 것 입 니 다.
링크:http://cs.usfca.edu/~cruse/cs635/
이 프로그램의 내용 은:
//-------------------------------------------------------------------
//	mycat.c
//
//	This program shows how the default behavior of the standard
//	UNIX/Linux 'cat' command could readily be implemented in C.  
//	(Consult the 'man' page for 'cat' to see the 'options' that 
//	would need to be added to achieve a total 'cat' emulation.)
//
//		compile using:  $ gcc mycat.c -o mycat
//		execute using:  $ ./mycat <filename>
//
//	programmer: ALLAN CRUSE
//	written on: 24 AUG 2007
//-------------------------------------------------------------------

#include <fcntl.h>	// for open() 
#include <stdio.h>	// for perror() 
#include <unistd.h>	// for read(), write(), close() 

int main( int argc, char *argv[] )
{
	int	i, fd, ch;	// declare local variables

	for (i = 1; i < argc; i++)
		{
		fd = open( argv[i], O_RDONLY );
		if ( fd < 0 ) { perror( argv[i] ); continue; }
		while ( read( fd, &ch, 1 ) == 1 ) 
			write( STDOUT_FILENO, &ch, 1 );
		close( fd );
		}
}

그 중에서 read 가 받 은 내용 을 표준 출력 으로 출력 할 때 write (STDOUT FILENO, & ch, 1) 를 사용 하고 출력 을 특정한 파일 로 재 설정 할 수 있 습 니 다.
pcie 데이터 전송 프로그램 을 작성 할 때 10 진법 으로 받 은 것 을 문자 로 변환 해서 파일 에 저장 하 는 것 이 생각 났 습 니 다. 여 기 는 STDOUT 로 출력 한 다음 에 파일 로 다시 설정 하면 목적 을 달성 할 수 있 을 것 같 습 니 다.이것 이 바로 풋내기 가 기본 시스템 프로 그래 밍 을 모 르 는 비극 이다. 너무 많은 시간 이 걸린다.

좋은 웹페이지 즐겨찾기