关于fork的个人理解

代码如下所示: #include #include #include #include #include #include void sig_chi

代码如下所示:

#include 
#include 
#include 
#include 
#include 
#include void sig_child()
{
    printf("child terminated\r\n");
}int main(int argc, const char *argv[])
{
    int pipefd[2];
    char buf[100]={0};
    pid_t pid;    // Create a pipe for interprocess communication
    if(pipe(pipefd)<0)
    {
        perror("pipe");
        exit(EXIT_FAILURE);
    }    // Create a process use fork
    pid=fork();    if(pid > 0)
    {
#if 0
    printf("###id=[%d]###\n",pid);
    printf("###pid=[%d]###\n",getpid());
    printf("###ppid=[%d]###\n",getppid());
#endif
        printf( "This is in the father process,here write a string to the pipe.\n" );  
        char buf[] = "Hello world , this is write by pipe.\n";  
        write( pipefd[1], buf, sizeof(buf) );