왜 PIPE가 깨지는건가요?? ㅜㅜ

익명 사용자의 이미지

초보 유닉스 네트워크 프로그래머입니다...

간단한 서버 프로그램을 짜서 테스트 중인데 자꾸 프로세스들이 죽어버리네요...
(defunct...)

죽는 이유를 알아보려고 strace해보니 파이프가 깨진다고 나옵니다... 이유가 뭘까요...

다음은 strace한 것 중에 파이프 깨지는 부분입니다
24164 select(2, [0 1], NULL, NULL, {5, 470000}) = 1 (in [1], left {5, 470000})
24163 <... nanosleep resumed> NULL) = 0
24164 time([1027645403]) = 1027645403
24163 nanosleep({0, 1000000},
24164 recv(1, "", 1024, 0) = 0
24164 send(1, "", 0, 0) = 0
24164 write(1, "\n", 1) = 1
24164 write(1, "\6\n", 2) = 2
24164 time([1027645403]) = 1027645403
24164 select(2, [0 1], NULL, NULL, {5, 470000}) = 1 (in [1], left {5, 470000})
24164 time([1027645403]) = 1027645403
24164 recv(1, 0xbffff6a0, 1024, 0) = -1 EPIPE (Broken pipe)
24164 send(1, "\6", 4294967295, 0) = -1 EPIPE (Broken pipe)
24164 --- SIGPIPE (Broken pipe) ---
24163 <... nanosleep resumed> 0) = -1 EINTR (Interrupted system call)
24163 --- SIGCHLD (Child exited) ---
24163 nanosleep({0, 1000000}, NULL) = 0.

익명 사용자의 이미지

문제는 다른곳에 있습니다.

일반적으로 tcp/ip통신에서 disconnect된 port를
정확히 처리를 하지 않으면 위와 같은 상황이 발생합니다.

발생이유
app --> tcp(트랜스포크계층) --> ip --> data link(H/W)....
위의 상황중 app --> tcp의 구조가 pipe로 구성 되어 있고,
tcp모듈이 disconnect를 인지하면 app와의 pipe는 절단 됩니다.
하지만 app는 그상황에 적절히 처리를 해주지 않고 있는 상태에서
자료를 전송 하려면 위와 같은 SIGPIPE신호(signal)을 받게 되는 겁니다.

해결방법
1. 자료전송시 sigpipe신호를 캐취하여 적절히 처리해준다.
(signal 캐취 부분 추가)
2. disconnect를 적절히 처리 해준다.
disconnect된 상황을 알 수 있는 가장 쉬운 방법은
read시 size가 0으로 되돌아 오게 된다.(pipe의 속성)

익명 사용자의 이미지

감사합니다...

많은 도움이 되었네요...

꾸벅~ (--) (__) (--)

댓글 달기

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