IPC FIFO READ()함수 질문이 있습니다.

xoduddk123의 이미지


http://forum.falinux.com/zbxe/index.php?document_srl=420145&mid=C_LIB

위의 링크를 보면서 IPC FIFO를 통해서 두개의 프로세스간에 통신을 하고자하고있습니다.

A라는 프로그램을 receiver로 돌리고 B라는 프로그램을 sender로 보낸다고 가정하였습니다.

제가 원하는 프로그램은 A프로그램에서 while(1) 무한반복문을돌면서 fifo파일을 읽어서 fifo에 저장되어있는 값을 토대로 각 경우에 맞게끔 실행하는것입니다.

그런데 프로그램을 돌려보니 read함수에서 sender의 입력을 계속 기다리다가 B라는 sender프로그램을 실행시켜야만 read함수를 실행하고 다음함수들로 진행되는것을 확인하였습니다.

제가생각하느 FIFO는 FIFO파일에 값이 저장되면 read함수가 FIFO파일에 저장되어있는 값을 토대로 read한다고 생각하고있었는데

read함수에서 sender프로그램의 write를 계속 기다리면서 멈춰있으니 생각대로 프로그램이 잘 작동을 하지않습니다

방법이 있을까요??

소스코드 첨부합니다.

[main_receiver.c]
#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define FIFO_FILE "/tmp/fifo"
#define BUFF_SIZE 16

struct data{
int AUTO;
int TIME;
int BRIGHT;
int LEVEL;
};

int main()

{

int fdd;
char bufff[BUFF_SIZE];
struct data data;
struct data data1;

if ( -1 == mkfifo( FIFO_FILE, 0666))
{
perror( "mkfifo() 실행에러");
exit( 1);
}

if ( -1 == ( fdd = open( FIFO_FILE, O_RDWR)))
{
perror( "open() 실행에러");
exit( 1);
}

data.AUTO=1;
data.TIME=1;
data.BRIGHT=1;
data.LEVEL=1;

TMP:
printf("TMP\n");

memset( &data, 0, BUFF_SIZE);

printf("\n\n\n * * * init * * *\n");
printf("receiver AUTO=%d\n",data.AUTO);
printf("receiver TIME=%d\n",data.TIME);
printf("receiver BRIGHT=%d\n",data.BRIGHT);
printf("receiver LEVEL=%d\n",data.LEVEL);
printf(" * * * E N D * * *\n");

while(1){
read( fdd, &data, sizeof(data));

printf("\n\n\n * * * teste * * *\n");
printf("receiver AUTO=%d\n",data.AUTO);
printf("receiver TIME=%d\n",data.TIME);
printf("receiver BRIGHT=%d\n",data.BRIGHT);
printf("receiver LEVEL=%d\n",data.LEVEL);
printf(" * * * E N D * * *\n");

}

close(fdd);

}

[main_sender.c]
#include
#include
#include
#include
#include

#define FIFO_FILE "/tmp/fifo"

struct data{
int AUTO;
int TIME;
int BRIGHT;
int LEVEL;
};
int main(int argc, char* argv[])
{
struct data data;

data.AUTO=atoi(argv[1]);
data.TIME=atoi(argv[2]);
data.BRIGHT=atoi(argv[3]);
data.LEVEL=atoi(argv[4]);
printf("\n\n * * * sender * * * \n");
printf("AUTO = %d\n",data.AUTO);
printf("TIME = %d\n",data.TIME);
printf("BRIGHT = %d\n",data.BRIGHT);
printf("LEVEL = %d\n",data.LEVEL);
printf("* * * E N D * * *\n\n");

int fd;

if ( -1 == ( fd = open( FIFO_FILE, O_RDWR)))
{
perror( "open() 실행에러");
exit( 1);
}

write( fd, &data, sizeof(data)/*strlen( value)*/);

}

xoduddk123의 이미지

read함수 블록킹 현상인거같은데 FIFO에서 어떻게 해결해야하나요 ㅠㅠ

xoduddk123의 이미지

open()을 O_RDONLY로 하여서 해결하였습니다.

댓글 달기

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