/createfile.c*/
#include<stdio.h>
#Include<unistd.h>
#include<stdlib.h>
void main()
{
int fd;
if((mkdir("mydir",0777))=-1) /* mydir is a new directory name to be created */
{
printf(|\n error in creating a directory");
exit(1);
}
if((creat("mydir/raj",0777))=-1) /* create a file named raj in directory mydir */
{
printf("\n error in creating a file");
exit(1);
}
sleep(60); /* the next statement get executed after 60 seconds */
unlink("mydir/raj"); /* remove the file raj in directory mydir
}
/* when executing this program open two terminals and in first terminal execute the program*/
/* open another terminal and check the existence of the file raj in directory mydir */
TERMINAL1
home/anil/~ cc createfile.c
/home/anil/~ ./a.out
-
TERMINAL2
/home/anil/~ cd mydir
/home/anil/mydir/~ ls
raj
signals
directory handling system calls, unix prorgam to create a file and then removes a file , creat system call, mkdir system call, unlink system call, UNIX program to create a file in the directoy, UNIX program to create a new directory, Unix program to print directory structure, opendir(), readdir()
No comments:
Post a Comment