½ø³Ì¹ÜÀíµÄÒ»¸öСÎÊÌâ
ÎÒʹÓõÄÊÇredhat8.0,ÔÚÒ»±¾ÊéÉÏÓиö¼òµ¥µÄ¹ØÓÚ½ø³Ì¹ÜÀíµÄÀý×Ó,µ«ÊÇÎÒÓÃgcc±àÒëÊÇÈ´²»ÕýÈ·,Ï£Íû´óϺ°ïæ½â´ðÒ»ÏÂ#include<unistd.h>
#include<stdio.h>
char string1[]="Hello";
char string2[]="World.";
int main(void)
{
pid_t PID;
PID=fork();
if(PID==-1)
{
perror("fork error ");
exit(1);
}
if(PID==0)
printf("%s",string1);
else
printf("%s",string2);
exit(0);
}
ÔÚ±àÒëµÄÊä³öÀïÃæÖ¸³ö²»ÈÏʶ"pid_t"
ÇëÎÊÕâ¸öÊÇʲô±êÖ¾,»¹ÓÐunistd.hÊÇÒ»¸ö¹ØÓÚʲôµÄÍ·º¯Êý. #include <stdlib.h>
pid_t is a process identification,it's defined as:
typedef int __pid_t
typedef __pid_t pid_t
unistd.h includes all the system call functions
Ò³:
[1]