FIFO 테스트

익명 사용자의 이미지

서버
#include
#include
#include
#include

int main( int argc , char *argv[] )
{
int i , fd , nread;
char buf[10 + 1];
if ( mkfifo( "myfifo" , 0777 ) == -1)
perror("mkfifo fail");
else
fprintf ( stderr , "fifo Successfully created!!
\n" );

//fd = open ( "myfifo" , O_RDONLY ); /* 상대방쪽에서
O_WRONLY로 open할때까지 blocking */
fd = open ( "myfifo" , O_RDWR ); /* 자체적으로 WR을 포함하
므로 blocking 되지 아니함 */
if ( fd == -1 )
perror ( "open fail" );
else
fprintf ( stderr , "opened Successfully \n" );

for ( memset( buf , 0 , sizeof buf );
/*
* O_RDONLY 상대방에서 write를 끝낸후에는 read
가 바로 0을 리턴하므로 종료됨
* O_RDWR 상대방에서 write를 끝낸후에도 자체 WR때문
에 블럭킹되어 종료하지 않음
*/
nread = read( fd , buf , sizeof buf - 1) ;
memset( buf , 0 , sizeof buf )
)
{
fprintf(stderr , "received Msg[%s] bytes[%d]\n" , buf , nread );
}
return 0;
}

클라이언트
#include
#include
#include
#include

FILE *fp;
int main( int argc , char *argv[] )
{
int i , fd , nwrite;
char buf[255];
fd = open ( "myfifo" , O_WRONLY|O_NONBLOCK );
if ( fd == -1 )
perror ( "open fail" );
else
fprintf ( stderr , "opened Successfully \n" );

if ( argc == 2 )
{
nwrite = write( fd , argv[1] , strlen( argv[1] ) );
fprintf ( stderr , "send msg[%s] bytes[%d]\n" , argv[1] , nwrite );
}
else
{
fp = fopen( "a.c" , "r" );
while ( fgets( buf , sizeof buf , fp ) )
{
//buf[strlen(buf)-1] = 0x00;
nwrite = write( fd , buf , strlen( buf ) );
fprintf ( stderr , "send msg[%s] bytes[%d]\n" , buf , nwrite );
}
fclose(fp);
}
return 0;
}

익명 사용자의 이미지

클라이언트를 컴파일 후에 실행시키면

세그먼트 폴트가 일어나는데

왠지 fgets때문인것두 같구여..

solaris 8에서 gcc 3.x로 컴파일 했거든여..

else이후를 주석으로 바꿔주면 잘 돼던데...

아시는 분 좀 알려주세여

익명 사용자의 이미지

아마도 ./client로 실행했고, 디렉토리내에 a.c가 없어서 일듯 하군요

실행방법을 ./client sdflkjasdf;asdjkl 로 하시거나

아니면 a.c 라는 더미파일 하나 만드시고 내용 대충 채우신 후에

그냥 ./client로 실행하심 될듯 한데요..

그럼..

댓글 달기

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