Skip to main content

Write programs to demonstrate communication between two processes. First process while send content of file to second process. Second process displays content by changing case.

#include
#include
#include

main(int agrc,char *argv[])
{
    int fd[2],pid,n,f,ch;
    char buffer[2048],*cha;

    if(pipe(fd)==-1)
    {
        printf(" problem to create the pipe \n ");
        exit(0);
    }
    else
    {
        pid=fork();

        if(pid!=0)
        {

            close(fd[0]);
            f = open("hardik",O_RDONLY);
            while((n = read(f,buffer,2048)) > 0)
            {
                write(fd[1],buffer,n);
            }
            close(fd[1]);
        }
        else
        {
            close(fd[1]);
            ch = 0;
            while((n=read(fd[0],cha,1)) > 0)
            {
                if(*cha >= 'a' && *cha <= 'z')
                {
                    printf("%c",*cha - 32);
                }
                else if(*cha >= 'A' && *cha <= 'Z')
                {
                    printf("%c",*cha + 32);
                }
                else
                {
                    printf("%c",*cha);
                }
            }
            close(fd[0]);
        }

    }
}

Comments