100% found this document useful (1 vote)
192 views

R23 LAB MANUAL

operating systems lab manual

Uploaded by

jayasree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
192 views

R23 LAB MANUAL

operating systems lab manual

Uploaded by

jayasree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

UNIX Operating System


Lab Manual

II B.Tech II Semester (R23 Regulation)

IDEAL INSTITUTE OF TECHNOLOGY


VIDYUTHNAGAR, KAKINADA
S.No. Name of the program Page No.

Practicing of Basic UNIX Commands


1
Write programs using the following UNIX operating system calls
2
fork, exec, getpid, exit, wait, close, stat, opendir and readdir

3 Simulate UNIX commands like cp, ls, grep, etc.,

Simulate the following CPU scheduling algorithms a) FCFS b) SJF


4
c) Priority d) Round Robin
Control the number of ports opened by the operating system with a)
5
Semaphore b) Monitors.
Write a program to illustrate concurrent execution of threads using
6
pthreads library.
Write a program to solve producer-consumer problem using
7
Semaphores.
Implement the following memory allocation methods for fixed
8
partition a) First fit b) Worst fit c) Best fit

Simulate the following page replacement algorithms a) FIFO b)


9
LRU c) LFU

10 Simulate Paging Technique of memory management.


Implement Bankers Algorithm for Dead Lock avoidance and
11
prevention
Simulate the following file allocation strategies a) Sequential b)
12
Indexed c) Linked
Download and install nachos operating system and experiment with
13
it
1.Practicing of Basic UNIX Commands

AIM: To study about the basics of UNIX

a) date
used to check the date and time
Syn:$date
Format Purpose Example Result
+%m To display only month $date+%m 06
+%h To display month name $date+%h June
+%d To display day of month $date+%d O1
+%y To display last two digits of years $date+%y 09
+%H To display hours $date+%H 10
+%M To display minutes $date+%M 45
+%S To display seconds $date+%S 55

b) cal
used to display the
calendar Syn:$cal 2
2009

c) echo
used to print the message on the screen.
Syn:$echo

d) ls
used to list the files. Your files are kept in a directory.
Syn:$lsls s
All files (include files
with prefix) ls l
Lodetai (provide file
statistics) ls t Order
by creation time
ls u Sort by access time (or show when last accessed
together with l) ls s Order by size
ls r Reverse order
ls f Mark directories with /,executable with* , symbolic links with @, local
sockets with =, named pipes(FIFOs)with
ls s Show file size
ls h Human Readable , show file size in Kilo Bytes & Mega Bytes (h can be used
together with l or)
ls[a-m]*List all the files whose name begin with alphabets From
to m ls[a]*List all the files whose name begins with A
Eg:$ls>my li ommand is stored to disk file named y l

e) lp
used to take
printouts
Syn:$lp
filename
f)man
used to provide manual help on every UNIX commands.
Syn:$man unix command
$man cat

g) who & whoami


it displays data about all users who have logged into the system currently. The
next command displays about current user only.
Syn:$who$whoami

h) uptime
tells you how long the computer has been running since its last reboot or power-off.
Syn:$uptime

i) uname
it displays the system information such as hardware platform, system name and
processor, OS type.
Syn:$uname a

j) hostname
displays and set
system host name Syn:$
hostname

k) bc
stands calculator

$bc $ bc $ bc $ bc
10/2*3 scale =1 ibase=2 sqrt(196)
15 2.25+1 obase=16 14 quit
3.35 11010011
quit 89275
1010

Quit
$bc $ bc-l
for(i=1;i<3;i=i+1)I scale=2
1 s(3.14)
2 0
3 quit
FILE MANIPULATION COMMANDS
a) cat this create, view and concatenate files.
Creation:
Syn:$cat>filename

Viewing:
Syn:$cat filename
Add text to an existing file:
Syn:$cat>>filename

Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)

b) grep used to search a particular word or pattern related to that word


from the file. Syn:$grep search word filename
Eg:$grep anu student

c) rm deletes a file from


the file system Syn:$rm
filename

d) touch used to create a blank file.


Syn:$touch file names

e) cp copies the files


or directories Syn:
$cpsource file
destination file Eg:
$cp student stud

f) mv to rename the
file or directory syn:
$mv old file new file
Eg:$mv i student student list(-i prompt when overwrite)

g) cut it cuts or pickup a given number of character or


fields of the file. Syn:$cut<option><filename>
Eg: $cut c filename
$cut c1-10emp
$cut f 3,6emp
$ cut f 3-6 emp
-c cutting columns
-f cutting fields

h) head displays10 lines from the


head(top)of a given file Syn:$head filename
Eg:$head student
To display the top two lines:

Syn:$head-2student

i) tail displays last 10


lines of the file Syn:
$tail filename
Eg:$tail student
To display the bottom two lines;
Syn:$ tail -2 student
j) chmod used to change the permissions of a file
or directory. Syn:$ch mod category
operation permission file Where, Category
is the user type
Operation is used to assign or remove
permission Permission is the type of
permission
File are used to assign or remove permission all

Examples:
$chmodu-wx student
Removes write and execute permission for users
$ch modu+rw,g+rwstudent
Assigns read and write permission for users and groups
$chmodg=rwx student
Assigns absolute permission for groups of all read, write and execute permissions

k) wc it counts the number of lines, words, character in a


specified file(s) with the options as l,-w,-c

Category Operation Permission


u users +assign r read
g group -remove w write
o others =assign absolutely x-execute

Syn: $wc l filename


$wc w filename
$wc c filename
AIM: To write C Programs using the following system calls of UNIX operating system fork,
exec, getpid, exit, wait, close, stat, opendir, readdir.

2. PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEMS (OPENDIR,


READDIR, CLOSEDIR)

PROGRAM:
#include <stdio.h>
#include <dirent.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[100];
DIR *dirp;
printf(“\n\n ENTER DIRECTORY NAME”);
scanf(“%s”, buff);
if((dirp=opendir(buff))==NULL)
{
printf(“The given directory does not exist”);
exit(1);
}
while(dptr=readdir(dirp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}
OUTPUT:

PROGRAM FOR SYSTEM CALLS OF UNIX OPERATING SYSTEM (fork, getpid, exit)

PROGRAM:
#include<stdio.h>
#include<unistd.h>
main()
{
int pid,pid1,pid2;
pid=fork();
if(pid==-1)
{
printf(“ERROR IN PROCESS CREATION \n”);
exit(1);
}
if(pid!=0)
{
pid1=getpid();
printf(“\n the parent process ID is %d\n”, pid1);
}
else
{
pid2=getpid();
printf(“\n the child process ID is %d\n”, pid2);
}
}

OUTPUT:

You might also like