Demo entry 6787136



Submitted by STC on Apr 10, 2019 at 04:22
Language: C. Code size: 689 Bytes.

if(pid < 0){  
        printf("Fork error!\n");  
        return -1;  
    }else if(pid == 0){  
        printf("Hello from child process, pid = %d\n", getpid());  
        printf("Child: waiting for message...\n");    
        byteSize = read(rw[0], buf, sizeof(buf));  
        printf("Child: received \"%s\"\n",buf);  
        printf("This is parent process, pid = %d\n", getpid());  
        printf("Parent: sending message...\n");  
        strcpy(buf,"Message from parent! ");  
        byteSize = write(rw[1], buf, sizeof(buf));  
        printf("Parent: send %d bytes to child.\n",byteSize);     

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).