2012-02-29 5 views
0

내 OS에 N 개의 파일 설명자가 있다고 가정 해 봅시다. 얼마나 많은 파일 기술자 OS는 아래의 코드를 실행 한 후에해야합니다 :C의 파일 설명자

int fd = dup(oldfd); 

방법에 대해 :

int fd = dup2(oldfd,newfd); 

감사합니다!

+0

직접 사용해 보지 않겠습니까? – talnicolas

+1

숙제가 있습니까? 내 시스템 프로그래밍 클래스처럼 들리네. – Coeffect

+0

숙제가 아니며 PC에 c 컴파일러가 설치되어 있지 않습니다. –

답변

3

설명서 페이지에 있습니다. 둘 중 하나를 호출 한 후 N+1 개의 파일 설명자가 있습니다.

From manpages 
    ... 
    dup and dup2 create a copy of the file descriptor oldfd. 

    After successful return of dup or dup2, the old and new descriptors 
    may be used interchangeably. 

    dup uses the lowest-numbered unused descriptor for the new descriptor. 
    ... 

이렇게 사용되지 않은 디스크립터는 새로운 디스크립터로 사용됩니다. 귀하의 질문에 대답해야합니다.