½ÃÀÛÆäÀÌÁö·Î Áñ°Üã±âÃß°¡
·Î±×ÀÎ
ȸ¿ø°¡ÀÔ l Ã⼮üũ l ¸¶ÀÌÆäÀÌÁö l CGIMALL
ÀÚ·á½Ç »çÀÌÆ®µî·Ï ·©Å·100 ÇÁ·Î±×·¥¸®ºä °ü¸®ÀÚÃßõÀÚ·á Ãʺ¸°¡À̵å
Ä¿¹Â´ÏƼ
Àüü ÆîÃ帱â
Äü¸Þ´º¸µÅ© jquery , CSS , PHP , Javascript , ¹«·áÆùÆ® , ASP
»ó¼¼°Ë»ö
Ȩ > Ä¿¹Â´ÏƼ > Áú¹®°ú´äº¯ »ó¼¼º¸±â
Ä¿¹Â´ÏƼ ±¸Àα¸Á÷
»çÀÌÆ®µî·Ï
Ŭ¶ó¿ìµåű×
javascript
php
ASP
css
mysql
html
jquery
������
image
Mobile
API
slide
°Ô½ÃÆÇ
ÇöÀçÁ¢¼ÓÀÚ ¸í »õ·Î°íħ
°Ô½ÃÆÇŸÀÌƲ Áú¹®°ú´äº¯ / »ó¼¼º¸±â
Æ®À§ÅÍ·Î º¸³»±â
Ãßõ¼ö 33 | Á¶È¸¼ö 354 | µî·ÏÀÏ 2001-04-07 07:51:28

´Ð³×ÀÓ

HappyCGI

À̸ÞÀÏ

hero@happycgi.com

Á¦¸ñ

[´äº¯] foke() ¸¦ ½ÇÇàÇؼ­ ÀÚ½ÄÇÁ·Î¼¼½ºÀÇ pid¸¦ Àâ´Â ¹ý
³»¿ë
¾È³çÇϼ¼¿ä. ÇØÇÇCGI À¥¸¶½ºÅÍ À±¿µ¿õÀÔ´Ï´Ù.
ÆÞ¸¶´Ï¾Æ¿¡¼­ ¹ßÃéµÈ ±ÛÀÔ´Ï´Ù.

fork¸¦ »ç¿ëÇÏ´Â ÀÌÀ¯´Â »õ·Î¿î ÄÁ³Ø¼ÆÀº ¸Î±â À§ÇÑ°ÅÁÒ.
°£´ÜÇÑ »ç¿ë¹ýÀº ´ÙÀ½°ú °°½À´Ï´Ù.

if(!defined($ChildPid=fork()) {
  die "cannot fork\n";
}
else {
if($ChildPid) {  # Parent Process

  }
  else {          # Child Process

  }
}

fork·Î »õ·Î¿î ÇÁ·Î¼¼½º°¡ »ý¼ºµÇ¸é ¿ø ÇÁ·Î¼¼½º(ºÎ¸ð ÇÁ·Î¼¼½º)ÀÇ fork´Â child processÀÇ pid¸¦ ¹ÝȯÇÏ°í, »ý¼ºµÈ(ÀÚ½Ä ÇÁ·Î¼¼½º)ÀÇ fork´Â 0À» ¹ÝȯÇÕ´Ï´Ù.
¹ÝȯµÈ PID¸¦ °¡Áö°í¼­ ÀÚ½ÅÀÌ ºÎ¸ð ÇÁ·Î¼¼½ºÀÎÁö, ÀÚ½Ä ÇÁ·Î¼¼½º ÀÎÁö ±¸º°ÇÏÁÒ.

¼ÒÄÏÀÇ °æ¿ì ºÎº¸ ÇÁ·Î¼¼½º´Â ´ÙÀ½ ÄÁ³Ø¼ÇÀ» ±â´Ù¸®°í, ÀÚ½Ä ÇÁ·Î¼¼½º´Â ÄÁ³Ø¼ÇÀ» ¸Î¾î¼­ µ¥ÀÌŸ¸¦ ÁÖ°í ¹Þ°í.. ÇÒÀÏ ÇÏÁÒ.

Á»ºñ ÇÁ·Î¼¼½º´Â ÇÁ·Î¼¼½º°¡ Á¾·á됬´Âµ¥, ±× ÇÁ·Î¼¼½º¸¦ »ý¼º½ÃŲ ÇÁ·Î¼¼½º°¡ ±× µÞÀÏÀ» ó¸®ÇÏÁö ¾ÊÀ¸¸é »ý±é´Ï´Ù. ÀÚ½Ä ÇÁ·Î¼¼½º°¡ ÀÚ±â ÇÒ ÀÏ ´Ù ³¡³»°í Á¾·áÇߴµ¥, ºÎ¸ð ÇÁ·Î¼¼½º°¡ ³ª¸ô¶óÇÏ¸é ±×³ðÀÌ Á»ºñ°¡ µÇ¼­ ¸®¼Ò½º ¹Ýȯ ¾ÈÇÏ°í ¹®Á¦°¡ µÇ±âµµ ÇÕ´Ï´Ù.

´ÙÀ½Àº °£´ÜÇÑ ¼­¹ö ¼Ò½ºÀÔ´Ï´Ù.

È­ÀÏ À̸§ : server.pl

#!/usr/bin/perl

$|=1;

use IO::Socket;

$Local = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>"1234", Listen=>1)
  or die "Can't open socket\n";
while($Remote = $Local->accept) {
  $Remote->autoflush(1);
  print "Connected\n";
  if(!defined($ChildPid=fork())) {
    die "cannot fork\n";
  }
  elsif($ChildPid) {    # Parent Process
    while(`ps axw|grep server|grep Z|grep -v grep|wc`/1 > 0) { wait; }
  }
  else {                # Child Process
    $Input=<$Remote>;
    print "INCOMING : $Input\n";
    print $Remote "HI! I am Server. my pid is $ChildPid\n";

    print "Connection Closed\n";
    close ($Remote);
    exit;
  } 
}

close $Local;

exit;

»ç½Ç Àúµµ Á»ºñ ¶§¹®¿¡ °í¹ÎÇؼ­ ´ÙÀ½°ú °°ÀÌ Ã¼Å© Çؼ­ ó¸®Çß½À´Ï´Ù. Á¦´ë·Î ó¸®ÇÑ °ÍÀº ¾Æ´Ñµ¥.. ÇÏ¿©°£¿¡ Á»ºñ¸¦ ¾ø¾Ö±â´Â ÇØ¿ä.

while(`ps axw|grep server.pl |grep Z|grep -v grep|wc`/1 > 0) { wait; }

ÇÁ·Î¼¼½º Áß¿¡ server.pl(ÇÁ·Î±×·¥À̸§ÀÌÁÒ)ÀÌ µé¾î°£°Í ´Ù ã°í, ±× Áß¿¡ Á»ºñ(Z·Î Ç¥½ÃµÇÁÒ)¸¦ ã¾Æ¼­ ±× °¹¼ö°¡ 1°³ ÀÌ»óÀ̸é, wait·Î Á»ºñ¸¦ ó¸®ÇÏ°í.
±×·±µ¥ ÀÌ·¸°Ô Çϸé ÀÚ½Ä ÇÁ·Î¼¼½º°¡ Á¾·áµÇÀÚ ¸¶ÀÚ Ã³¸®ÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó, ´ÙÀ½ ÄÁ³Ø¼Ç¶§ ó¸®ÇÏ´Â °Å¶ó¼­ Á¦´ë·Î µÈ ¹æ¹ýÀÌ ¾Æ´ÏÁÒ. ¿µ ÂóÂóÇϱä Çѵ¥.

°ü·ÃµÈ ¹®¼­°¡ ÀÖ±ä Çѵ¥, Á¤¸®°¡ ¾ÈµÈ°Å¶ó ÀÚ·á½Ç¿¡µµ ¿Ã¸®Áö ¸øÇÏ°í...
¸ÞÀÏ ¾îµå·¹½º ÁÖ½Ã¸é ¸ÞÀÏ·Î º¸³»µå¸±²²¿ä.

ÁñÆÞ!
Ãßõ½ºÅ©·¦¼Ò½ºº¸±â ¸ñ·Ï
ÀÌÀü°Ô½Ã±Û »ó¼¼ÇÑ ´äº¯¿¡ °¨»çµå¸³´Ï´Ù. 2001-04-07 01:12:21
´ÙÀ½°Ô½Ã±Û cgiÇÁ·Î±×·¥ ±¸ÇÕ´Ï´Ù.(±×¸² ÂüÁ¶) 2001-04-07 12:43:16