From 2e77c76192362d2e39c249d22e7381c3dfa690b3 Mon Sep 17 00:00:00 2001 From: Elaiyavan-k Date: Tue, 27 May 2025 09:08:58 +0530 Subject: [PATCH] Update README.md --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d38d99b..5f3d1dc 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,81 @@ Execute the C Program for the desired output. ## 1.To Write a C program that illustrates files copying +``` +#include +#include +#include +#include +int main() +{ + char block[1024]; + int in, out; + int nread; + in = open("filecopy.c", O_RDONLY); + out = open("file.out", O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); + while((nread = read(in,block,sizeof(block))) > 0) + write(out,block,nread); + exit(0);} +``` +## 2.To Write a C program that illustrates files locking +``` +#include +#include +#include +#include +#include +int main (int argc, char* argv[]) +{ + char* file = argv[1]; + int fd; + struct flock lock; + printf ("opening %s\n", file); + fd = open (file, O_WRONLY); + if (flock(fd, LOCK_SH) == -1) + { + printf("error"); + } + else + { + printf("Acquiring shared lock using flock"); + } + getchar(); + if (flock(fd, LOCK_EX | LOCK_NB) == -1) + { + printf("error"); + } + else + { + printf("Acquiring exclusive lock using flock"); + } + getchar(); + if (flock(fd, LOCK_UN) == -1) + { + printf("error"); + } + else + { + printf("unlocking"); + } + getchar(); + close (fd); + return 0; +} +``` +## OUTPUT -## 2.To Write a C program that illustrates files locking - - +### 01 +![image](https://github.com/Priyanghaofficial/Linux-File-IO-Systems-locking/assets/147121154/a14ff10d-b16b-4403-ab3a-639485382e02) -## OUTPUT +### 02 +![image](https://github.com/Priyanghaofficial/Linux-File-IO-Systems-locking/assets/147121154/6a9674ab-333d-4bb8-be25-8f3e8bef5530)