Hai there studs....I know how hard it is to deal with computer science lab sessions in the Indian Engineering scenario. I wished if someone would literaly  give those codes to the programs that we require...
But when we search for programs we mostly end up at question answer sections of many famous computer science based blogs and websites which defenetly is a great help for those who know how to make up an entire program from bits............... for those who dont well now I am here....
Well I am no expert either but I can assure you that the programs that I am posting here are those for which I got a valid result and an authorized signature....BINGO so here goes.

A few tips....
       ->I run most programs in ubuntu so here is how to run them in terminal
       ->open terminal use Ctrl+Alt+T
       ->change the directory to the folder where you have originally kept  
           the file using cd command
       ->type gcc filename.c to compile the program
       ->if no errors are reported type ./a.out to execute the program


PROGRAMS

1. Process Creation Using Fork

#include<stdio.h>
#include<unistd.h>
main()
{
    int p;
    pid_t pid1,pid2;
    pid1=fork();
    if(pid1==0)
    {
        printf("child1\n");
        pid2=fork();
        if(pid2==0)
        {
            printf("child1's child\n");
        }
        else
        {
            wait(&p);
            printf("child1\n");
        }
    }
    else
    {
        wait(&p);
        printf("parent1\n");
    }
}

2.Inter Process Communication Using Unidirectional Pipe

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>

main()
{
    int fd[2];
    pid_t childpid;
    char string[] = "Hello World!\n";
    char readbuffer[100];
   
    pipe(fd);
    childpid=fork();
    if (childpid==-1)
    {   
        perror("fork");
        exit(0);
    }
   
    if (childpid==0)
    {
        close(fd[0]);
        write(fd[1],string,strlen(string));
        exit(0);
    }
    else
    {
        close(fd[1]);
        read(fd[0],readbuffer,sizeof(readbuffer));
        printf("Recieved string is : %s \n", readbuffer);
    }
   
    return 0;
}

3.Inter Process Communication Using Bidirectional Pipe

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<string.h>
main()
{
    int fd1[2],fd2[2];
    pid_t childpid;
    char string1[]="I am child\n";
    char string2[]="I am parent\n";
    char readbuffer[100];
    pipe(fd1);
    pipe(fd2);
    childpid=fork();
    if(childpid==-1)
    {
        printf("fork error\n");
        exit(0);
    }
    else if(childpid==0)
    {
        close(fd1[0]);
        write(fd1[1],string1,strlen(string1));
        close(fd2[1]);
        read(fd2[0],readbuffer,sizeof(readbuffer));
        printf("child message is : %s\n",readbuffer);
    }
    else
    {
        close(fd2[0]);
        write(fd2[1],string2,strlen(string2));
        close(fd1[1]);
        read(fd1[0],readbuffer,sizeof(readbuffer));
        printf("parent message is : %s\n",readbuffer);
    }
    return 0;
}


NOTE:MORE POSTS WILL FOLLOW

Comments