read() 함수에서 decriptor 관련 질문입니다.

익명 사용자의 이미지

ssize_t read(int fd, void *buf, size_t count) 의 원형을 보면

fd의 따라서 file or socket 따라 다른 동작을 합니다.

여기서 궁금 한 것이 있는데

1. decriptor(여기서 fd)가 file descriptor 인지 socket descriptor 인지

어떻게 구별을 하나요?

커널에서 자체적으로 구별을 하는 건가요?

구별 할 수 있는 함수가 존재 하는 건가요?

2. 느낌으로 분명히 read() 함수의 구현 부분을 보면 알 수 있을 것 같은
데.. -_-;;;

어떤 파일에 read()가 구현이 되어 있나요?

경로까지 알려 주시면 감사하겠습니다 (_ _)

익명 사용자의 이미지

file descriptor과 socket descriptor는 생성하는 것 부터 다릅니다.

file descriptor는 open(), fopen()과 같은 함수로 생성되구요

socket descriptor는 socket()를 통해서 생성됩니다.

같은 file descriptor table을 사용하지만.. 엄연히 차이가 잇슴돠..

글구.. read() 함수는여

/usr/include/unistd.h 에 정의되어 있습니다.

허접답변이었습니당.

즐겅... ( ^^)=b

익명 사용자의 이미지

struct stat statbuf;
fstat(fd, &statbuf);
is_socket = S_ISSOCK(statbuf.st_mode);
을 하시면 됩니다.
참고로 read함수 구현을 보셔도 전혀 알수가 없습니다.
단순히 kernel에게 요청하는게 전부랍니다.

겁쟁이 wrote..
ssize_t read(int fd, void *buf, size_t count) 의 원형을 보면

fd의 따라서 file or socket 따라 다른 동작을 합니다.


여기서 궁금 한 것이 있는데


1. decriptor(여기서 fd)가 file descriptor 인지 socket descriptor 인지

어떻게 구별을 하나요?


커널에서 자체적으로 구별을 하는 건가요?

구별 할 수 있는 함수가 존재 하는 건가요?


2. 느낌으로 분명히 read() 함수의 구현 부분을 보면 알 수 있을 것 같 은
데.. -_-;;;


어떤 파일에 read()가 구현이 되어 있나요?

경로까지 알려 주시면 감사하겠습니다 (_ _)

익명 사용자의 이미지

답변 감사합니다.

실제로 read() 관련된 설명을 보니

system_call을 호출하고

kernel에서 descriptor의 형태에 따라서 다른 동작을 한다고 나와있네
요 -)

즐거운 하루 되세요 ^^

댓글 달기

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