--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

¤­¤¯¤¿¤Ë¤Ç¤¹¡£

Á°¤Ë¤â¤Á¤ç¤Ã¤È¤¤¿¤³¤È¤¬¤¢¤ê¤Þ¤¹¤¬¡¢ÅºÉ¨Â¤Â¤ÎC program¤ò
Áö¤é¤»¤Æ¡¢»Ò¥×¥í¥»¥¹¤ÎźÉÕ2¤Îruby¥¹¥¯¥ê¥×¥È¤¬Ê¸»úÎó"ruby"¤ò
¼õ¤±¼è¤é¤Ê¤¤¤Î¤Ï¤Ê¤¼¤Ç¤·¤ç¤¦¡©

»÷¤¿¤è¤¦¤Ê¤³¤È¤òPython¤Ç¤ä¤ë¤ÈźÉÕ¤Î3ÈÖÌÜ¤ÇÆ°¤¯¤Î¤Ç¤¹¤±¤É¡£

-- 
¿ÍÀ¸¤òÇØÉ餤Åꤲ

µÆÃ« À¿(Kikutani Makoto)  kikutani / eis.or.jp hgf03701 / niftyserve.or.jp
                          http://www.eis.or.jp/muse/kikutani/

--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="ipc-test0.c"

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>

main()
{
   int pid, i, slen, l;
   char *cmd, *arg0, arg1[8], *str;
   int channel[2]; /* IPC channel with child process */
   char buf[10];

   if (socketpair(AF_UNIX, SOCK_STREAM, 0, channel) < 0) {
      fprintf(stderr, "socketpair failed\n");
      return;
   }

   if ((pid  fork()) -1) {
      return;
   }

   if (pid 0) {		/* child process */
#if 0
      cmd  ./ipc0";
      arg0  ipc0";
#else
      cmd  ./ipc0.rb";
      arg0  ipc0.rb";
#endif
      sprintf(arg1, "%d", channel[0]);
      execl(cmd, arg0, arg1, NULL);
      perror("execl failed");
      close( channel[0] );
      _exit( 1 );
   }

   /* parent process */	
   close(channel[0]);


   i  x12345678;
   if ((l  rite( channel[1], &i, sizeof(int))) ! izeof(int))
     printf("ipc-test0.c: int write failed. written length  %d\n", l);

   if ((l  ead( channel[1], buf, 2)) ! )
     printf("ipc-test0.c: int read failed. read length  %d\n", l);
   printf("buf  s\n", buf);

   str  ruby";
   slen  trlen(str);
   fflush(stdout);
   if ((l  rite( channel[1], str, slen)) ! len)
     printf("ipc-test0.c: str write failed. written length  %d\n", l);
   if ((l  ead( channel[1], buf, 2)) ! )
     printf("ipc-test0.c: int read failed. read length  %d\n", l);
   printf("buf  s\n", buf);

}

--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="ipc0.py"

#!/usr/bin/python
import sys,os,string

def read_int(fd):
    i  d.read(4)
    v  rd(i[3])
    v   * 256 + ord(i[2])
    v   * 256 + ord(i[1])
    v   * 256 + ord(i[0])
    return v

port  tring.atoi(sys.argv[1])
sys.stderr.write("port   + sys.argv[1] + "\n")

fd  s.fdopen(port, "r+")
i  ead_int(fd)
sys.stderr.write("i  x\n" % i)
fd.write("OK")

line  d.read(4)
sys.stderr.write("line   + line + "\n")
fd.write("OK")

--ZPt4rx8FFjLCG7dd--