Operating Systems Lab Report
Operating Systems Lab Report
Operating Systems
Lab Report
1- Introduction:
This lab was an introduction to LINUX Ubuntu operating system
which is a practical lab of the operating systems Course. In this lab we
have learned how to install LINUX using the Vmware Workstation by
creating a virtual Machine inside windows System and run it along side
with windows System. Later on we had learned some basic concepts on
Linux such like logging in to Linux system, Anatomy of Linux
Command, the Linux File-system, File Ownership and Permissions, the
$PATH environment variable, input and output redirection. After that we
did a lab on vi and gcc we did editing files using vi, deleting text and
undoing changes, moving around the file, and last thing we learned to
compile codes using gcc that’s to be starting to do the coming labs which
needs to compile and run files, lab 4 was on process, and then
communication between processes, lab 5 on POSIX Threads and
Synchronization, lab 7 was on memory management, lab 8 scheduling
with algorithms, and last lab was lab 9 on Input/Output.
2- Procedures:
Lab1, 2, and 3 all was about installing and running the system and
running the command lines and it is all a normal and easy things to be
done and in this step we just followed the instructions in the book.
Lab 4 we started to write the codes and compile it and run the result using
the command lines that shows after each one of the code lines.
For lab 5 and 6 we had to add some lines of codes by the guide of the
book instructions which can help the code to print out the correct result
Lab 7 and 8 I just copied the codes from the book and I runt it properly
but for lab 8 I had to add some codes to give ascending and descending
sort to the output.
Lab 9 I actually find some better codes in the internet and it was better
than the one in the book as I find from running it so I just add it there.
This was all the Procedures we done for this labs.
3- Source Code:
4-1. if(ret==0){
Name=”child”;
}else{
Name=”parent”;
Sleep(2);
4-2. fork();
Printf(“……..”);
Operating System
Exit(0);
4-3. fork();
fork();
Printf(“……..”);
Exit(0);}
4-4. pid = fork();
If(pid<0){
#block of code
}else if (pid == 0){
#block of code
}else{
#block of code
Exit(0);
4-5. if(fork()== 0)
Execv(“/bin/ls”, argv);
Wait(ststus);
Exit(status);
Exercise 4:
Pid = fork();
Switch(pid){
Case1:
….…….
Case0:
….…….
Default:
….…….
Break;
Wait();
Exit();
Exercise 5:
If(pid!=0);{
If(waitpid(-1,&status, 0)>0);
If(WIFEXTED(status)!=0);
Printf(“……….”);
}
}
Printf(“bey”);
Exit(2);
5-1.
If(pipe(pfd) == 1)
{
Exit(1);
}
If((pid = fork())<0){
Exit(2);
}
If(pi == 0){
}else
{
Operating System
5-2. if (fork() == 0)
{
#block of code
}else{
#block of code
}
5-4.if(pipe(fd) == 1){perror(“pipe failed”);exit(1);}
If((pid = fork())<0{perror(“pipe failed”);exit(2);}
If(pid != 0){
#block of code
}
else{
#block of code
}
Exercise 3:
If (key = ftok (“.”, s))==1){
#block of code
}
If((semid == segment(key,1IPC_CREATE|0666))==1){
#block of code
}
If(semct(semid,0,setval,semopts)==-1){
#block of code
}
While(1)
#block of code
}
Exit(0);
Exercise 4:
If(argc>1){
#block of code
}
If(msgid == -1){
#block of code
}
While(running){
If(msgrcv(msgid,(void*)&somedata,BUFSIZ, msgtorec,0)== -1)
#block of code
}
}
}
If(msgct(msgid,ipc,0)== -1)
#block of code}
Exercise 5:
If(shmid == -1){
#block of code
}
If(sahred-memory == (void*)-1){
#block of code
Operating System
}
While(running){
#block of code
.
.
.
}}}
7-1.
#include<stdio.h>
main(){
char *s;
char c;
s=(char *)0;
c= *s;
}
7-2.
#include<stdio.h>
extern end;
extern etext;
extern int I;
extern int j;
int I;
main(int argc, char **argv){
int i;
int *ii;
printf("&etext = 0x%Ix\n", &etext);
printf("&end = 0x%Ix\n", &end);
printf("\n");
ii = (int*)malloc(sizeof(int));
printf("main = 0x%Ix\n", main);
printf("&L =0x%Ix\n", &I);
printf("&i = 0x%Ix\n", &i);
printf("&argc = 0x%Ix\n", &argc);
printf("&ii = 0x%Ix\n", &ii);
printf("ii = 0x%Ix\n", ii);
}
7-3.
#include<stdio.h>
extern end;
extern etext;
main(){
char *s;
char c;
printf("&etext = 0x10c0c\n",&etext);
printf("&end = 0x20ee9\n",&end);
printf("\n");
printf("Enter memory location in hex (start with 0x):");
Operating System
fflush(stdout);
scanf("0x%x",&s);
printf("Reading 0x%x:",s);
fflush(stdout);
c=*s;
printf("%d\n",c);
printf("Writing %d back to 0x%x:",c,s);
fflush(stdout);
*s = c;
printf("ok\n");
}
7-4.
#include<stdio.h>
#include<string.h>
char secret[] = "jryy qbar ibhat cnqnjna!";
struct token {
char buf[15];
int pass;
};
}else if(*(str+i)>='n'&&*(str+i)<='z'){
*(str+i)-=13;
}else if(*(str+i)>='N'&&*(str+i)<='Z'){
*(str+i)-=13;
}else if(*(str+i)>='A'&&*(str+i)<='N'){
*(str+i)+=13;
}
}
}
int main(void){
struct token myToken;
myToken.pass = 0;
printf("the secret is reserved for those who can enter the password:\n");
gets(myToken.buf);
if(strcmp(myToken.buf, "iloveOS"))
{
Operating System
printf("\nincorrect password\n");
}else{
printf("npassword OK\n");
myToken.pass = 1;
}
if(myToken.pass){
rot13(secret,24);
printf("%s\n",secret);
}
return 0;
}
8-1.
#include<stdio.h>
void main()
{
int stt[20],ft[20],at[20],bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
stt[i] = wt[i];
}
8-2.
#include<stdio.h>
void main()
{
int stt[20],ft[20],at[20],bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
total+=wt[i];
stt[i] = wt[i];
}
9-1.
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
Operating System
#include<fcntl.h>
#include<errno.h>
#include<string.h>
#include<unistd.h>
#define BUFSIZE 14
int main(){
int fd;
char buf[BUFSIZE];
fd=open("file2.txt",O_RDONLY,6600);
read(fd,buf,BUFSIZE);
printf("%s",buf);
close(fd);
buf[BUFSIZE]='\0';
return 0;
}
9-2.
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
#include<string.h>
#include<unistd.h>
#define BUFSIZE 14
int main(){
int fd;
char buf[BUFSIZE];
fd=open("file.txt",O_RDONLY,6600);
int length=read(fd,buf,BUFSIZE);
close(fd);
for(int i=0;i<length;++i){
printf("%c",buf[i]);
}
buf[BUFSIZE]='\0';
return 0;
}
4- Sample Run:
Operating System
Operating System
Operating System
Operating System
Operating System
Operating System
Operating System
Operating System
Operating System
Operating System
5- Conclusion:
Actually we had learned a lot of concepts about LINUX in this lab which
helped us to more understand the different between all the operating
systems both the obvious and hidden things we had learned it by the hepl
of the teacher and I really enjoyed doing this labs even that I had to suffer
a lot to understand it bu at the end and by hard working I finally
understand it and I did it. Other thing we had learned is the work team
way and we understand the importance of working as a team so we can
finish the work on time and perfectly.
That’s all for this lab report all the thanks to the teacher, and I want to say
we all appreciate it all the help given by the teacher.