C Program using UNIX System Call


/* illustrating IPC through pipe and fork system calls – Printing only odd numbers */

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

int main()

{

int pfd[2], i;

pid_t mypid;

if(pipe(pfd) < 0)

perror(“Pipe Error”);

if(!fork())

{

char data;

printf(“Enter a Number…\n”);

scanf(“%d”, &data);

write(pfd[1], &data, 1);

mypid = getpid();

printf(“I am process %d\n”, mypid);

printf(“My parent is process %d\n”, getppid());

printf(“Child Exiting…\n”);

exit(0);

}

else

{

char data1;

read(pfd[0], &data1, 1);

printf(“Received %d from child \n”, data1);

printf(“The odd numbers are… \n”);

for(i=1; i<=data1; i+=2)

{

printf(“%5d”, i);

sleep(2);

}

printf(“\n Parent Exiting…\n”);

exit(0);

}

return(0);

}

3 Comments

  1. wat about grep simulation ………..

    program for memory management and file allocation technique please

  2. i want unix system calls program using fork,open,write,close,execv,read,getpid

  3. dear sir,
    i want java lab program for 5th sem cse syllabus.kindly do the needful


Sorry, the comment form is closed at this time.

Comments RSS