Implementation of mkdir command


/*Implementation of mkdir command */

#include<stdio.h>

#include<stdlib.h>

#include<sys/stat.h>

void usage(const char *myname)

{

printf(“\nUsage: %s <pathname> [<mode>]\n\n”, myname);

exit(1);

}

void main(int argc, char *argv[])

{

int mode;

if(argc<2)

usage(argv[0]);

if(argc==2)

mode = 0777;

elseif(sscanf(argv[2], “%o”, &mode==0)

{

printf(“%s : Invalid Mode\n”, argv[0]);

exit(1);

}

if(mkdir(argv[1], mode)== -1)

perror(argv[0]);

else

printf(“%s directory is created successfully”, argv[1]);

}

Implementation of Shared Memory Segment


//Shared Memory Segment

Program 1:

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/shm.h>

#include <stdio.h>

#include <sys/sem.h>

#define SHMSZ     27

main()

{

char c;

int semid,retval;

struct sembuf sop,sop1;

int shmid;

key_t key;

char *shm, *s;

key = 5678;

Continue reading

C Program using UNIX System Call


/* illustrating IPC through pipe and fork system calls – Printing only odd numbers */

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

int main()

{

int pfd[2], i;

pid_t mypid;

if(pipe(pfd) < 0)

perror(“Pipe Error”);

if(!fork())

{

char data;

printf(“Enter a Number…\n”);

scanf(“%d”, &data);

write(pfd[1], &data, 1);

mypid = getpid();

printf(“I am process %d\n”, mypid);

printf(“My parent is process %d\n”, getppid());

printf(“Child Exiting…\n”);

Continue reading

cat command simulation


//Simulation of cat command

#include<stdio.h>

#include<stdlib.h>

void printfile(FILE *f)

{

char str[80];

while(fgets(str,80,f))

printf(“%s”, str);

}

int main(int argc, char *argv[])

{

char str[80];

FILE *f;

if(argc<2)

printfile(stdin);

else

{

int i;

Continue reading

ls command simulation


//Simulation of ls command

#include<stdio.h>

#include<dirent.h>

#include<unistd.h>

#include<sys/types.h>

int main(int c, char *argv[])

{

DIR *ptr;

int i=0;

struct dirent *p;

ptr = opendir(“.“);

p = readdir(ptr);

if((c!=1) && (strcmp(argv[i]), “-a” == 0))

{

while(p!=NULL)

{

printf(“%s\n”, p->d_name);

p=readdir(ptr);

}

}

Continue reading

C Program using I/O System Calls


//To do open, read and write operations on a file

#include <unistd.h>

#include <fcntl.h>

#include <string.h>

#include <stdio.h>

int main()

{

int fd[2];

char buf1[25] = “just a test\n”;

char buf2[100];

fd[0] = open(“tfile”,O_RDWR);

fd[1] = open(“tfile”,O_RDWR);

write(fd[0],buf1,strlen(buf1));

printf(“\nEnter your text now…”);

gets(buf1);

write(fd[0],buf1,strlen(buf1));

write(1, buf2, read(fd[1],buf2,sizeof(buf2)));

close(fd[0]);

close(fd[1]);

printf(“\n”);

return 0;

}

CS 47-OPERATING SYSTEMS LAB


CS 47                        OPERATING SYSTEMS LAB                       0 0 3 2

(Common to CSE & IT)

(Implement the following on LINUX or other Unix like platform. Use C for high level language implementation)

  1. Write programs using the following system calls of UNIX operating system: fork, exec, getpid, exit, wait, close, stat, opendir, readdir
  2. Write programs using the I/O system calls of UNIX operating system (open, read, write, etc)
  3. Write C programs to simulate UNIX commands like ls, grep, etc.
  4. Given the list of processes, their CPU burst times and arrival times, display/print the Gantt chart for FCFS and SJF. For each of the scheduling policies, compute and print the average waiting time and average turnaround time. (2 sessions)
  5. Given the list of processes, their CPU burst times and arrival times, display/print the Gantt chart for Priority and Round robin. For each of the scheduling policies, compute and print the average waiting time and average turnaround time. (2 sessions)
  6. Developing Application using Inter Process communication (using shared memory, pipes or message queues)
  7. Implement the Producer – Consumer problem using semaphores (using UNIX system calls).
  8. Implement some memory management schemes – I
  9. Implement some memory management schemes – II

10.  Implement any file allocation technique (Linked, Indexed or Contiguous)

Continue reading