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
-
UpdatedOct 23, 2014
-
Views2,419
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.