You are on page 1of 21

CODING:

#main()
{
printf "user profile \n"
printf "Enter name:"; read name;
printf "Enter roll number:"; read no;
printf "Enter branch:"; read bra;
printf "Enter mobile number:"; read mo;
printf "Enter address:"; read ad;
printf "Enter pincode:"; read pin;

echo "Name: $name">a.profile


echo "Roll number: $no">>a.profile
echo "Branch: $bra">>a.profile
echo "Mobile number: $mo">>a.profile
echo "Address: $ad">>a.profile
echo "Pincode: $pin">>a.profile
echo "\n\nYou Enter your profile is...:"
uniq a.profile
}

OUTPUT:

mint@mint:~$ sh a.sh
user profile
Enter name:palanisamy
Enter roll number:106mc159
Enter branch:mca
Enter mobile number:9500203185
Enter address:403 kamaraj street
Enter pincode:638502

You Enter your profile is...:


Name: palanisamy
Roll number: 106mc159
Branch: mca
Mobile number: 9500203185
Address: 403 kamaraj street
Pincode: 638502

RESULT:

Thus the program executed and verified result successfully by using shell
programming.
VIVA QUESTIONS:
1. What do you mean by operating system?
Operating system is the software that controls the computer hardware. It
acts as an interface between computer hardware and the user.

2. Give some examples for Operating system?


There are large numbers of OS. Microsoft’s Windows XP, Windows Vista
and Red Hat’s Linux are famous OS in nowadays.

3. When and where the UNIX was developed?


The UNIX OS was originally designed in the late 1960s and early 1970s
at AT&T Bell Laboratories.

4. What is Kernal?
Kernal is the central part of the UNIX OS. It encapsulates the hardware
and provides UNIX system services to applications programs.

5. Explain the types of Operating system.

 Simple batch systems


 Multiprogramming systems
 Time sharing systems

6. What is a time sharing system?


Time-sharing or multitasking is a logical extension of multiprogramming. It
allows many users to share the computer simultaneously. The CPU executes multiple
jobs by switching among them, but the switches occur so frequently that the users can
interact with each program while it is running
7. What do you mean by command interpreter?

One of the most important systems programs for an operating system


is the command interpreter, which is the interface between the user and the
operating system.

8. What is Shell?
The Shell is the UNIX system’s mechanism for interfacing between users
and the system. It is a command interpreter.

9. Explain the types of Shell?


UNIX system support several different shells. Three of the most popular
shells are:
1. the Bourne shell,
2. the Berkeley C shell, and
3. the Korn shell.

10. What are the services provided by Operating system?


The services are:
1. Program execution,
2. I/O operations,
3. File system manipulation,
4. Communications,
5. Error detection,
6. Resource allocation,
7. Accounting, and
8. Protection.

11. What is Grep command?


grep command is used to search pattren within a file.
Syntax: grep "pattren" filename
CODING:

new()
{
echo "Enter file name to create"; read name;
clear
echo ''>$name;
while :
do
read a
case $a in [qQ]|[qQ][uU][iI][tT]) break;;
*) echo $a>>$name;;
esac
done
}
display()
{
echo "Enter file name to open"; read name;
if test [-f $name]
then
uniq $name;
fi
}
canc()
{
echo "Enter file name to append"; read name;
clear
uniq $name;
while :
do
read a
case $a in [qQ]|[qQ][uU][iI][tT]) break;;
*) echo $a>>$name;;
esac
done
}
#main()
{
while :
do
echo "\n\t\t menu\n\t\t----\n=> [1] Create\n=> [2] Display\n=> [3] Append\n=> [4]
Exit\nEnter choice...:"
read cmd
case $cmd in [1]) new;;
esac
case $cmd in [2]) display;;
esac
case $cmd in [3]) canc;;
esac
case $cmd in [4]) exit;;
esac
done
}

OUTPUT:

menu
----
=> [1] Create
=> [2] Display
=> [3] Append
=> [4] Exit
Enter choice...:
1
Enter file name to create
aa

hi friends this is new unix editor


pls type quit to quit
quit

menu
----
=> [1] Create
=> [2] Display
=> [3] Append
=> [4] Exit
Enter choice...:
2

Enter file name to open


aa

hi friends this is new unix editor


pls type quit to quit

menu
----
=> [1] Create
=> [2] Display
=> [3] Append
=> [4] Exit
Enter choice...:
3
Enter file name to append
aa

hi friends this is new unix editor


pls type quit to quit
we can uppend data here again
quit

menu
----
=> [1] Create
=> [2] Display
=> [3] Append
=> [4] Exit
Enter choice...:
4

RESULT:

Thus the program executed and verified result successfully by using shell
programming.
VIVA QUESTIONS:
. What is process?
Ans: A process can be thought of as a program in execution. It is an active entity ,
with a
program counter specifying the next instruction to execute. The execution of a process
must
be sequential.

2. List the states of process?


Ans: There are five states:
• New ,
• Running,
• Waiting,
• Ready, and
• Terminate.

3. What are the operations possible in process?


Ans: Creating a process, and Destroying a process.

4. What is child process?


Ans: A child process is an almost exact copy of a process created by
forking. The child
process, however, has its own unique process id, and maintains a
reference to the parent's
process id.
5.. What is processor sharing?
Ans: The performance of the RR algorithm depends heavily on the size of the
time quantum. If the time quantum is very large, the RR policy is same as the FCFS
policy. If the time quantum is very small, the RR approach is called processor
sharing.
6. What are the information’s stored in PCB?
Ans: Process state, CPU registers, CPU-scheduling information, memory
management information, accounting information.

7. What are all the events may occur when process is assigned to CPU?
Ans:
1. The process could issue an I/O request, and then be placed in an I/O queue.
2. The process could create a new sub process and wait for its termination.
3. The process could be removed forcibly from the CPU, as a result of an interrupt,
and be put back in the ready queue.

8. What is the use of job queues?


Ans: As a process enters a system they are put in to a job queue. These queues
consist of
all jobs in the system.

9. What is the use of ready queue?


Ans: The processes that are residing in main memory and are ready and waiting
to
execute are kept on a list called ready queue.

10. What is the use of device queue?


Ans: The list of processes waiting for particular I/O devices kept in the device
queue.
Ex.No: 5 Inter process Communications

AIM:

To write a c program to perform the Inter process Communication using message


queue.

ALGORITHM:

STEP 1: Start the program execution.


STEP 2: Declare the variables.
STEP 3: Create a message queue.
STEP 4: Get the messages using message queue.
STEP 5: Send and receive the message.
STEP 6: Stop the program execution.

CODING:

#include<sys/ipc.h>
#include<sys/msg.h>
#include<stdio.h>
void main()
{
int qid,i;
struct
{
long mtype;
char mtext[25];
}
message;
struct
{
long mtype;

char mtext[25];
}buff;
qid=msgget((key_t)3,IPC_CREAT|0666);
if(qid==1)
{
perror("Msgget Failed");
exit(1);
}
strcpy(message.mtext,"First Message");
message.mtype=1;
if(msgsnd(qid,&message,21,0)==-1)
{
perror("Msgsnd Failed");
exit(1);
}
strcpy(message.mtext,"Second Message");
message.mtype=2;
if(msgsnd(qid,&message,21,0)==-1)
{
perror("Msgsnd Failed");
exit(1);
}
strcpy(message.mtext,"Third Message");
message.mtype=3;
if(msgsnd(qid,&message,21,0)==-1)
{
perror("Msgsnd Failed");
exit(1);
}
qid=msgget((key_t)3,IPC_CREAT|0666);
if(qid==-1)
{
perror("Msgget Failed");
exit(1);
}
for(i=0;i<3;i++)
{
if(msgrcv(qid,&buff,15,0,IPC_NOWAIT|MSG_NOERROR)==-1)
{
perror("msgrcv failed");
exit(1);
}
printf("Message is %s\n",buff.mtext);
}
}

OUTPUT:

[root@localhost ~]# ./a.out


Message is First Message
Message is Second Message
Message is Third Message

RESULT:

Thus the inter process communication using message queue was performed.
VIVA QUESTIONS:

1. Write a command to display a file’s contents in various formats?

$od -cbd file_name


c - character, b - binary (octal), d-decimal, od=Octal Dump.

2. What will the following command do?

$ echo *
It is similar to 'ls' command and displays all the files in the current directory.

3. Is it possible to create new a file system in UNIX?

Yes, ‘mkfs’ is used to create a new file system.

4. Is it possible to restrict incoming message?

Yes, using the ‘mesg’ command.

5. What is the use of the command "ls -x chapter[1-5]"

ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to
'5', chapter1, chapter2, and so on.

6. Is ‘du’ a command? If so, what is its use?

Yes, it stands for ‘disk usage’. With the help of this command you can find the disk
capacity and free space
of the disk.

7. Is it possible to count number char, line in a file; if so, How?

Yes, wc-stands for word count.


wc -c for counting number of characters in a file.
wc -l for counting lines in a file.

8. Name the data structure used to maintain file identification?


‘inode’, each file has a separate inode and a unique inode number

9. How to terminate a process which is running and the specialty on command kill 0?

With the help of kill command we can terminate the process.


Syntax: kill pid Kill 0 - kills all processes in your system except the login shell.

10. What is a pipe and give an example?

A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the
output of
the preceding command to be passed as input to the following command.
VIVA QUESTIONS:

1. Explain kill() and its possible return values.

There are four possible results from this call: ‘kill()’ returns 0. This implies that a process
exists with the given PID, and the system would allow you to send signals to it. It is system-
dependent whether the process could be a zombie.

2. What is relative path and absolute path.

Absolute path : Exact path from root directory.


Relative path : Relative to the current path.
Ex.No: 7 Allocation of Disk blocks

AIM:

To develop a shell program for Allocation of Disk blocks

ALGORITHM:

STEP 1: Start the program execution.


STEP 2: Declare the variables.
STEP 3: Create a message queue.
STEP 4: Get the messages using message queue.
STEP 5: Send and receive the message.
STEP 6: Stop the program execution.
CODING:

#!/bin/sh
echo "Disk Hogs Report for System `hostname`"

bigdir2="`du -s /Library/* | sed 's/ /__/g' | sort -rn | cut -f2- | head -5`"

echo "The Five biggest library directories are:"


echo $bigdir2

for dirname in $bigdir2 ; do


echo ""
echo Big directory: $dirname
echo Four largest files in that directory are:
find "`echo $dirname | sed 's/__/ /g'`" -type f -ls | \
awk '{ print $7" "$11 }' | sort -rn | head -4
done

exit 0

OUTPUT:

The Five biggest home directories are:


/home/staging /home/chatter /home/cbo /home/sherlockworld /home/launchline

Big directory: /home/staging


Four largest files in that directory are:
423 /home/staging/waldorf/big/DSCF0165.jpg
410 /home/staging/waldorf/big/DSCF0176.jpg
402 /home/staging/waldorf/big/DSCF0166.jpg
395 /home/staging/waldorf/big/DSCF0161.jpg

Big directory: /home/chatter


Four largest files in that directory are:
1076 /home/chatter/comics/lynx
388 /home/chatter/logs/access_log
90 /home/chatter/logs/error_log
64 /home/chatter/responding.cgi

Big directory: /home/cbo


Four largest files in that directory are:
568 /home/cbo/financing.pdf
464 /home/cbo/investors/CBO-plan.pdf
179 /home/cbo/Archive/cbofinancial-modified-files/CBO Website.zip
77 /home/cbo/Archive/cbofinancial-modified-files/CBO Financial Incorporated .doc
Big directory: /home/sherlockworld
Four largest files in that directory are:
565 /home/sherlockworld/originals-from gutenberg.txt
56 /home/sherlockworld/speckled-band.html
56 /home/sherlockworld/copper-beeches.html
54 /home/sherlockworld/boscombe-valley.html

Big directory: /home/launchline


Four largest files in that directory are:
151 /home/launchline/logs/access_log
71 /home/launchline/x/submit.cgi
71 /home/launchline/x/admin/managesubs.cgi
64 /home/launchline/x/status.cgi

RESULT:

Thus the program executed and verified result successfully by using shell
programming.
VIVA QUESTIONS:

1. What is memory management?


Memory management is the act of managing computer memory. In its simpler
forms, this involves providing ways to allocate portions of memory to programs at their
request, and freeing it for reuse when no longer needed. The management of main
memory is critical to the computer system.

2. What is virtual memory?

Virtual memory systems separate the memory addresses used by a process from
actual physical addresses, allowing separation of processes and increasing the effectively
available amount of RAM using disk swapping. The quality of the virtual memory
manager can have a big impact on overall system performance.

3. What is the difference between logical and physical addresses?

An address generated by the CPU is commonly referred to as a logical address,


whereas an address seen by the memory unit is commonly referred to as physical
address.

4. What are steps done by address binding?

a. Compile time
b. Load time
c. Execution time.

5. What is shared memory?

shared memory is a memory that may be simultaneously accessed by multiple


programs with an intent to provide communication among them or avoid redundant
copies. Depending on context, programs may run on a single processor or on multiple
separate processors. Using memory for communication inside a single program, for
example among its multiple threads, is generally not referred to as shared memory.
6. What you mean by buffer?

A buffer is a large block of memory from which blocks are allocated contiguously,
as a simple technique for fast allocation.

7. Define cache memory.

A processor's memory cache is a small piece of fast, but more expensive


memory, usually static memory, used for copies of parts of main memory. The cache is
automatically used by the processor for fast access to any data currently resident there.
Access to the cache typically takes only a few processor clock cycles, whereas access to
main memory may take tens or even hundreds of cycles.

8. What do you mean by best fit?

The Best fit allocates the smallest hole that is big enough. Entire list has to be
searched, unless it is sorted by size. This strategy produces smallest leftover hole.

9. What do you mean by first fit?

First fit allocates the first hole that is big enough. Searching can either start at the
beginning of the set of holes or where the previous first-search ended. Searching can
be stopped as soon as a free hole that is big enough is found.
10. What is external fragmentation?

External fragmentation exists when enough total memory space exists to satisfy a
request, but it is not contiguous; storage is fragmented into a large number of small
holes.
Ex.No: 8 “ls -l” command

AIM:

To develop an utility that outputs the same information and


in the same format as the “ls -l” command

ALGORITHM:

STEP 1: Start the program execution.


STEP 2: Declare the variables.
STEP 3: Create a message queue.
STEP 4: Get the messages using message queue.
STEP 5: Send and receive the message.
STEP 6: Stop the program execution.
CODING:

Coding:-
lsl()
{
ls -l > a
uniq a
rm a
}

#main()
{
lsl
}

OUTPUT:

mint@mint:/media/Amp/unix$ sh lsl.sh
total 480
-rwx------ 1 mint root 0 2011-01-30 17:54 a
-rwx------ 1 mint root 88 2011-01-29 23:00 aa
-rwx------ 1 mint root 844 2011-01-29 21:33 ex3.txt
-rwx------ 1 mint root 670 2011-01-29 23:31 ex41.sh
-rwx------ 1 mint root 670 2011-01-29 23:31 ex41.sh~
-rwx------ 1 mint root 698 2011-01-29 23:27 ex4.sh
-rwx------ 1 mint root 700 2011-01-29 23:26 ex4.sh~
-rwx------ 1 mint root 765 2011-01-29 23:00 ex4.txt
-rwx------ 1 mint root 765 2011-01-29 23:00 ex4.txt~
-rwx------ 1 mint root 308 2011-01-30 11:35 ex5.sh
-rwx------ 1 mint root 310 2011-01-30 11:33 ex5.sh~
-rwx------ 1 mint root 261 2011-01-30 11:37 expect.sh
-rwx------ 1 mint root 0 2011-01-30 11:38 in.fifo
-rwx------ 1 mint root 49 2011-01-30 17:52 lsl.sh
-rw------- 1 mint root 44 2011-01-30 17:52 lsl.sh~
-rwx------ 1 mint root 0 2011-01-30 17:53 lsl.tst
-rwx------ 1 mint root 0 2011-01-30 11:38 out.fifo
-rwx------ 1 mint root 277 2011-01-30 11:40 PIPE0
-rwx------ 1 mint root 1 2011-01-30 11:37 Unsaved Document 1~

RESULT:

Thus the program executed and verified result successfully by using shell
programming.
VIVA QUESTIONS:

1. What do you mean by compaction?

Compaction is a solution to external fragmentation. The memory contents are


shuffled to place all free memory together in one large block. It is possible only if
relocation is dynamic, and is done at execution time.

2. Explain briefly the main concept of paging?

Paging is a memory management scheme that permits the physical-address space


of a process to be noncontiguous. In the case of paging, physical memory is broken
into fixed-sized blocks called frames and logical memory is broken into blocks of the
same size called pages.

3. How is memory protected in a paged environment?

Protection bits that are associated with each frame accomplish memory protection
in a paged environment. The protection bits can be checked to verify that no writes are
being made to a read-only page.

4. What is the use of valid-invalid bits in paging?

When the bit is set to valid, this value indicates that the associated page is in
the process’s logical address space, and is thus a legal page. If the bit is said to
invalid, this value indicates that the page is not in the process’s logical address space.
Using the valid-invalid bit traps illegal addresses.

5. What is the basic method of segmentation?

Segmentation is a memory management scheme that supports the user view of


memory. A logical address space is a collection of segments. The logical address
consists of segment number and offset. If the offset is legal, it is added to the segment
base to produce the address in physical memory of the desired byte.
6. What is virtual memory?

Virtual memory is a technique that allows the execution of processes that may not
be completely in memory. It is the separation of user logical memory from physical
memory. This separation provides an extremely large virtual memory, when only a
smaller physical memory is available.

7. What is Demand paging?

In Demand paging, the pager brings only those necessary pages into memory
instead of swapping in a whole process. Thus it avoids reading into memory pages that
will not be used anyway, decreasing the swap time and the amount of physical
memory needed.

8. How does page replacement takes place in optimal algorithm?

In Optimal algorithm, it replaces the page that will not be used for the longest
period of time. Optimal algorithm has the lowest page-fault rate of all algorithms.

9. What is the disadvantage of optimal page replacement algorithm?

Even though optimal algorithm has the smallest page fault-rate, it is difficult to
implement, because it requires future knowledge of the reference string. As a result, it
is used mainly for comparison studies.

10. What you mean by backing store?

Backing store is typically part of a hard disk that is used by a paging or


swapping system to store information not currently in main memory. Backing store is
slower and cheaper than main memory.

You might also like