select 함수 관련 질문입니다..

jungjury의 이미지

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
 
#include <stdio.h>
 
int main()
{
        fd_set read_fds;
        fd_set write_fds;
        int ret;
 
        FD_ZERO( &read_fds );
        FD_SET( 0, &read_fds );
        FD_SET( 1, &read_fds );
 
        FD_ZERO( &write_fds );
        FD_SET( 0, &write_fds );
        FD_SET( 1, &write_fds );
 
        ret = select ( 2, NULL, &write_fds, NULL, NULL );
 
 
        printf( "ret =  %d \n", ret );
 
        if ( ret > 0 )
        {
                if ( FD_ISSET( 0, &read_fds ) )
                        printf( "read from 0\n" );
                if ( FD_ISSET( 1, &read_fds ) )
                        printf( "read from 1\n" );
                if ( FD_ISSET( 0, &write_fds ) )
                        printf( "write to 0\n" );
                if ( FD_ISSET( 1, &write_fds ) )
                        printf( "write to 1\n" );
 
        }
}

실행시키면
ret = 2
write to 0
write to 1

아래로 바꾸어 실행하면
ret = select ( 2, &read_fds, NULL, NULL, NULL );

hi <--hi입력
ret = 4
read from 0
read from 1
write to 0
write to 1

STDIN과 STDOUT이 버퍼를 같이 써서 이런 상황이 발생하는 건가요?

park7275의 이미지

일단은 select 에 parameter 로 넣지 않은 값은.. 무의미할듯한데요
해당값은 call by reference로 처리하는 값입니다.

그니깐..

ret = select ( 2, NULL, &write_fds, NULL, NULL );
할때 read_fds 값의 FD_ISSET은 무의미 하지 않나요?

ret = select ( 2, &read_fds, NULL, NULL, NULL );
할때 write_fds도 마찬가지고요.

select 에 parameter로 넣지 않은것을 FD_ISSET 을 검사하는 것은 무의미 합니다.
어떤 반응이 나올지는 kernel에 따라 다를수 있지 않을까 싶네요.
원래 FD_SET으로 한값이 나올것 같은데..

근데..나온 결과로는...모르겠네요.

밑에 결과가 4라는 것은 read_fds와 write_fds가 2개씩 등록되어있으니
select에서 parameter 로 2개 다 사용했을때 나오지 않을까 싶은데...
넣지도 않은 값이 나왔다는게..이상..--;

FD_SET이 다른건가?? 좀 애매하네요..ㅜㅜ

[KILL] 죽을각오로.........

[KILL] 죽을각오로.........

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.