Design and Develop a program to demonstrate use of fork() and exec() to create a new directory.

AIM:

Design and Develop a program to demonstrate use of fork() and exec() to create a new directory.

Program:

#include<stdio.h>
int main( )
{
   int td;
   if (fork()!=0)
   {
     wait((int *)0);
   }
   else
   {
     execl(“/bin/mkdir”,”mkdir”,"nerodisk”,(char*)NULL);
     Fprint(stderr,”exec failed !\n”);
     exit(1);
   }
   If((fd=open(“newdir/too.bar",o_FDWR | O_CREATE,0644))== -1)
   {
     fprintf(stderr,”open failed !\n”);
     exit(2);
   }
     write(fd,”Hello, world \n”,1&);
     close(fd);
     exit(0);
}

Output:

Student@ubuntu:~$ gcc –o fe.out fe.c
Student@ubuntu:~$ ./fe.out
Student@ubuntu:~$ cd dirs
Student@ubuntu:~$cat too
Hello world