message queue 에 관하여

mr.lee의 이미지

오랜만에 IPC설비를 사용할 일이 있어서 어떤것을 사용할지 검토하던중 메세지큐에서 헷갈리는 부분이 2개 있어서 질문드립니다.

1.
메세지버퍼가 다음과 같다고 했을때.
struct msgbuf {
long mtype;
char mtext[..];
};

struct msgbuf BUF;

man을 보면 msgsnd, msgrcv 등의 함수 3번째 인자인 size_t msgsz(메세지사이즈) 의 값이 sizeof(struct msgbuf)가 아니라 sizeof(BUF.mtext) 의 의미로 나오는데 보통들 사용할때 struct의 크기를 많이 사용하던데 문제는 없는건지요?

2. struct msgbuf에서 long mtype만 필수이고 나머진 실상 원하는데로 멤버를 만들어도 된다고 알고 있었는데

struct msgbuf {
long mtype;
int a;
};

뭐 이런식으로 테스트를 해보면 런타임에러가 나더군요?

cococo의 이미지

char mtext[] 를 빼는 건 시험 안 해 봤지만,
인자를 char []이외에 추가시키는 건 전에 직접 코드로 테스트 해 봤습니다. 됩니다.

단, 예를들어

struct msgbuf {
long mtype;
int a;
char b;
char mtext[..];
};

라고 하면, 크기를 인자로 전달 해 줄 때 sizeof( int + char + char [..]) 으로 해 주는 거랑, (즉, sizeof(msgbuf) - sizeof(msgbuf.mtype) )
char []이 가장 마지막(= msgbuf 선언부에서 가장 아래) 에 와야 한다는 것. 이 필요했었습니다.

라고 기억하고 있습니다.
설명을 매끄럽게 쓰지 못했는데, 몇 번 테스트 해보시면 금방 아실겁니다.

mr.lee의 이미지

음.그렇군요.
mtext[] 를 빼면 인자가 어떻다면서 실행에러가 나던데..
다른 멤버를 추가할때 mtext[]를 맨마지막에 놓아야 하는군요. 어째 이식성이 별로 없는 특성인듯하기도 한데..

젤 확실한건 mtext만 두고 (버퍼개념으로) 거기 실제 구조체내용을 담은다음 보내서 풀면 되겠지만.. msgbuf 구조체 자체를 실제 필요한 구조체로 쓸려고 하니.. 조금 더 테스트해봐야 겠네요.

여튼 인자의 크기에 mtype은 빠지는게 맞군요. 하긴 man에 그리 나와있으니.

댓글 달기

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