ºìÁªLinuxÃÅ»§
Linux°ïÖú

Çó°ïæ¸Ä³ÌÐò£¬°Ñ³ÌÐò¸ÄµÄ¸´ÔÓһЩ

·¢²¼Ê±¼ä:2011-06-28 17:33:36À´Ô´:ºìÁª×÷Õß:СµÏµÜµÜ
ÒªÇ󣺱àдһ¸ö³ÌÐò£¬ÔÚÖ÷½ø³ÌÖд´½¨Á½¸ö×Ó½ø³Ì£¬×Ó½ø³Ì1½øÐпÕÑ­»·£¬²»Í£µØÊä³ö¡°Hello£¬I am subprogram 1!¡±×Ö·û´®£¬×Ó½ø³Ì2½øÐпÕÑ­»·£¬²»Í£µØÊä³ö¡°Hello£¬I am subprogram 2!¡±×Ö·û´®,Ö÷½ø³ÌÐÝÃßÒ»¶Îʱ¼äºó£¬ÔÚÖ÷½ø³ÌÖнáÊø×Ó½ø³Ì£¬ËæºóÖ÷½ø³ÌÒ²Í˳ö¡£
×¢Ò⣺Ҫ½øÐÐ×Ó½ø³ÌµÄ²¢·¢¿ØÖÆ£¬ÒÔÃâÁ½¸ö½ø³ÌµÄÊä³ö½á¹û½»Ö¯ÔÚÒ»Æð¡£

³ÌÐò£º#include
#include
#include
#include
void child_function_one()
{

while(1)
{
printf("Hello ! I am subprogram 1! \n");
//kill(getpid(),SIGUSR1);
sleep(5);

}


//puts("Good bye! \n");
//exit(0);

}
void child_function_two()
{

while(1)
{
printf("Hello ! I am subprogram 2! \n");
//kill(getpid(),SIGUSR2);
sleep(5);


}
//puts("Good bye! \n");
//exit(0);
}
void main()
{
pid_t p1, p2;
p1=fork();

if (p1==0)
{
child_function_one();
}

p2=fork();

if (p2==0)
{
child_function_two();
}

sleep(10000);
kill(p1,SIGKILL);
kill(p2,SIGKILL);
}
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ