OS 4 and 8 PGM
OS 4 and 8 PGM
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FIFO_NAME "myfifo"
int main()
{
int fd;
char buffer[BUFSIZ];
// Writer process
if (fork() == 0)
{
printf("Writer process is running. Enter data to write (type 'exit' to quit):\n");
fd = open(FIFO_NAME, O_WRONLY);
if (fd == -1) {
perror("open"); exit(EXIT_FAILURE);
}
while (1) {
fgets(buffer, BUFSIZ, stdin);
close(fd);
}
// Reader process
else {
printf("Reader process is running. Reading data from the FIFO:\n");
fd = open(FIFO_NAME, O_RDONLY);
if (fd == -1) {
perror("open"); exit(EXIT_FAILURE);
}
while (1) {
if (read(fd, buffer, BUFSIZ) == 0) { break;
}
close(fd);
}
return 0;
}
Output
Lab 08) Simulate following File Organization Techniques
a) Single level directory b) Two level directory
Single level directory: In a single level directory system, all the files are
placed in one directory. This is very common on single-user OS's. A single-
level directory has significant limitations, however, when the number of
files increases or when there is more than one user. Since all files are in
the same directory, they must have unique names. If there are two users
who call their data file "test", then the unique-name rule is violated.
Although file names are generally selected to reflect the content of the
file, they are often quite limited in length. Even with a single-user, as the
number of files increases, it becomes difficult to remember the names of
all the files in order to create only files with unique names shown in below
figure.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int nf=0,i=0,j=0,ch;
char mdname[10],fname[10][10],name[10];
Input:
Enter the directory name:KLEIT
Enter the number of files:3
Enter file name to be created:CSE
Do you want to enter another file(yes - 1 or no - 0):1
Enter file name to be created:ECE
Do you want to enter another file(yes - 1 or no - 0):1
Enter file name to be created:MECH
Do you want to enter another file(yes - 1 or no - 0):0
Output:
Directory name is:KLEIT
Files names are:
CSE
ECE
MECH
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t");
}
printf("\n");
}
getch();
}
Input
enter number of directories:3
enter directory 1 names:VTU
enter size of directories:3
enter subdirectory name and size:CSE 2
enter file name:SEM1
enter file name:SEM2
enter subdirectory name and size:MECH 3
enter file name:SEM3
enter file name:SEM4
enter file name:SEM5
enter subdirectory name and size:ECE 1
enter file name:SEM6
enter directory 2 names:KLEIT
enter size of directories:2
enter subdirectory name and size:CSDEPT 2
enter file name:ABC
enter file name:ABD
enter subdirectory name and size:MECHDEPT 1
enter file name:ABCD
enter directory 3 names:BVBCET
enter size of directories:1
enter subdirectory name and size:SCIENCE 3
enter file name:PHY
enter file name:CHE
enter file name:MAT