unix assignment

59
UNIX AND SHELL PROGRAMMING 1. Why do we require system administration? Who can be a system administrator 2. Write a shell script to accept a number and a word as command line arguments and print the word the given number of times on each line. What happens if a number and a string is given as command line arguments? 3. List the building block primitives of UNIX with examples. 4. Kernel Iaid to be non-preemptive comment. Advantages and disadvantages of kernel data Structure 5. Write a shell script to find the file with the maximum size in the current directory. 6. Differentiate user mode & kernel mode 7. Draw a diagram process execution levels. 8. What are the 3 levels of UNIX operating system? 9. Define System call interface 10. What are the subsystems of UNIX OS? 11. Define Zombie State process transition 12. Write a shell script to find the number of ordinary files and directory in the current directory. 13. What is the first step in booting a UNIX OS? 14. Explain the details Operating System services. 15. Explain the details about process states & state Transition. 16. Write a shell script which accepts a number and displays the list of odd numbers below that number. 17. Explain the details about the User perspective 18. Write a shell script to accept the name of the directory as command line argument and display the

Upload: shwts12

Post on 04-Apr-2015

931 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Unix assignment

UNIX AND SHELL PROGRAMMING

1. Why do we require system administration? Who can be a system administrator

2. Write a shell script to accept a number and a word as command line arguments and print the word the given number of times on each line. What happens if a number and a string is given as command line arguments?

3. List the building block primitives of UNIX with examples.4. Kernel Iaid to be non-preemptive comment. Advantages and

disadvantages of kernel data Structure5. Write a shell script to find the file with the maximum size in the current

directory.6. Differentiate user mode & kernel mode7. Draw a diagram process execution levels.8. What are the 3 levels of UNIX operating system?9. Define System call interface10.What are the subsystems of UNIX OS?11.Define Zombie State process transition12.Write a shell script to find the number of ordinary files and directory in

the current directory.13.What is the first step in booting a UNIX OS?14.Explain the details Operating System services. 15.Explain the details about process states & state Transition. 16.Write a shell script which accepts a number and displays the list of odd

numbers below that number.17.Explain the details about the User perspective 18.Write a shell script to accept the name of the directory as command line

argument and display the long listing of that directory. By default the HOME directory’s contents should be displayed.

19.What does the kernel in buffer read-ahead?20.List out the various status of the buffer.21.State the advantages and disadvantages of buffer cache22.Define inode and inode cache23.What are the fields of super block?24.Explain the structure of buffer pool 25.Write a shell script to accept a number in the command line and

displays the sum up to that number.For example,if the number given is 20,then the sum of numbers 1,2,3…..20 should be displayed .By default,the sum upto 50 should be displayed.

Page 2: Unix assignment

26.What are the various services provided by an operating system?27.Define Mounting and Unmounting system call and their syntax.28.Explain how a file is mounted and unmounted from the file structure 29.Write a shell script to accept two filenames and check if both exist. If

the second filename exists, then the contents of the first filename should be appended to it. If he second filename does not exist then create a new file with the contents of first file.

30.What are the first 3 steps of process states and transition? Define context of the process

31.What are the different modes for working in vi? Explain other editors apart from vi .

32.Explain user priorities and kernel priorities33.Give different layers of UNIX Architecture.Explain the intended

purposes of each.

Page 3: Unix assignment

Q1)Why do we require system administration. Who can be a system administrator?

System administration plays a pivotal role. This is particularly the case when a system is accessed by multiple users. The primary task of a system administrator is to ensure that the following happens:

a. The top management is assured of efficiency in utilization of the system'sresources.

b. The general user community gets the services which they are seeking.In other words, system administrators ensure that there is very little to complain about thesystem's performance or service availability.

In Unix there is a notion of a superuser privilege. Most major administrative tasks require that the system administrator operates in the superuser mode with root privileges. These tasks include starting up and shutting down a system, opening anaccount for a new user and giving him a proper working set-up. Administration tasks also involve installation of new software, distributing user disk space, taking regular back-ups, keeping system logs, ensuring secure operations and providing network services and web access.

Page 4: Unix assignment

Q2)Write a shell script to accept a number and a word as command line arguments and print the word the given number of times on each line. What happens if a number and a string is given as command line arguments?

n=$1word=$2

while [ $n -gt 0 ]; do echo $word n=`expr $n - 1`done

Page 5: Unix assignment

Q3) List the building block primitives of UNIX with examples.

Unix enables to Write Small modular Program that can be Used as building block to build more complex programs. There 2 Primitives: 1. I/O redirection 2. Pipe(|)

I/O REDIRECTION Most unix command read input, such as a file or another attribute for the command, and write output. By default, input is being given with the keyboard, and output is displayed on your screen. Your keyboard is your standard input (stdin) device, and the screen or a particular terminal window is the standard output (stdout) device.

Output redirection with > and | : Sometimes you will want to put output of a command in a file, or you may want to issue another command on the output of one command. This is known as redirecting output. Redirection is done using either the “>” (greater-than symbol), or using the “|” (pipe) operator which sends the standard output of one command to another command as standard input. The file descriptor 0 is assigned to the standard output file.

Eg: cat1 test1 > test2

the cat command concatenates files and puts them all together to the standard output. By redirecting this output to a file, this file name will be created - or overwritten if it already exists, so take care.

Page 6: Unix assignment

Input redirection In another case, you may want a file to be the input for a command that normally wouldn't accept a file as an option. This redirecting of input is done using the “<” (less-than symbol) operator. The file descriptor 1 is assigned to the standard input file.

Eg: cat <test1

In this the cat will take each line of file test1 as input and display it on the monitor.

Error Redirection When invalid command is typed at the $prompt the shell displays error message on the monitor.Thus the monitor is reffered as standard error file. The file descriptor 2 is assigned to the standard error file.

PIPES Unix has a feature by which filters and other commands can be combined in such a way that the standard output of 1 filter command can be sent as standard input to another filter or command.

$ ls –l|wc –lIt is the command to display the no of total lines in current directory.

$ grep –n `and’ testCommand to display the no of lines where the word ‘and’ occurs in a file test.

Page 7: Unix assignment

Q5) Write a shell script to find the file with the maximum size in the current directory.

ls -l | grep -v ^d | awk '{print $5 " " $9 }' | sort -n | tail -n -1

Page 8: Unix assignment

Q6) Differentiate user mode & kernel mode ?

Kernel Mode (System Mode) a)In this mode executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address.

b)Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic , they will halt the entire PC.

c)When the CPU is in kernel mode, it is assumed to be executing trusted software, and thus it can execute any instructions and reference any memory addresses (i.e., locations in memory).

d)The kernel (which is the core of the operating system and has complete control over everything that occurs in the system) is trusted software, but all other programs are considered untrusted software.

Thus, all user mode software must request use of the kernel by means of a system call in order to perform privileged instructions, such as process creation or input/output operations.

User Mode :a)In User mode, the executing code has no ability to directly access hardware or reference memory. Code running in user mode must delegate to system APIs to access hardware or memory.

Page 9: Unix assignment

b)Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable. Most of the code running on your computer will execute in user mode.

Page 10: Unix assignment

Q7) Draw a diagram process execution levels.

Page 11: Unix assignment

Q8) What are the 3 levels of UNIX operating system?

KERNEL is a heart of unix operating system, it act as a interface between the computer hardware and user. In unix all the commands are accepted by sting operation. command interpreter(shell interpreter) want to execute the command in computer hardware. Here the kernel takes the commands by command interpretor(shell interpretor) and executes in computer hardware(where the unix is loaded)Finally it produce the result.The kernel handles the following operations :

1. It is responsible for scheduling running of user and other processes.

2. It is responsible for allocating memory.3. It is responsible for managing the swapping between

memory and disk.4. It is responsible for moving data to and from the

peripherals.5. it receives service requests from the processes and honors

them.

The kernel architecture must support the primary Unix requirements. These requirements fall in two categories namely, functions for process management and functions for file management (files include device files). Process management entails allocation of resources including CPU, memory, and offers services that processes may need.

Page 12: Unix assignment

The file management in itself involves handling all the files required by processes,communication with device drives and regulating transmission of data to and from peripherals.

Device Management handles the transfer of information between computer and terminal,tapes and drivers and printers.

SHELL

A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering command input as text for a command line interpreter to execute or by creating text scripts of one or more such commands.The most generic sense of the term shell means any program that users employ to type commands. In the Unix operating system users may select which shell to use for interactive sessions. When the user logs in to the system the shell program is automatically executed. Many types of shells have been developed for this purpose. The program is called a "shell" because it hides the details of the underlying operating system behind the shell's interface. The shell manages the technical details of the operating system kernel interface, which is to the lowest-level, or 'inner-most' component of an operating system.

Page 13: Unix assignment

Types of Shell

1)Bourne shell: The Bourne shell, sh, was written by Stephen Bourne at AT&T. sh is the original Unix command line interpreter; it introduced the basic features common to all the Unix shells, including piping, here documents, command substitution, variables, control structures for condition-testing and looping and filename wildcarding2)C shell: The C shell, csh, was written by Bill Joy while a graduate student at University of California, Berkeley. The language, including the control structures and the expression grammar, was modeled on C. The C shell also introduced a large number of features for interactive work, including the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job controland path hashing.3)Korn Shell:developed by David korn.this shell combines the best feature of bourne and c shell.It is slowly gaining popularity and its executable file name is ksh.4)Restricted shell:rsh is the restricted shell of bourne shell typically used for guest login ie users are not part of the system and also used in secure installation where users are restricted to work only in their environment.

TOOLS AND APPLICATIONS

Unix Os provides more than 1000 unix based application program as well as unix utilities or commands which are collection of 200 program that serves the day to day processing requirements. these programs are invoked through the shell which is itself another utility.

Page 14: Unix assignment

Q9) Define System call interface ?

The kernel lies between the underlying hardware and other high level processes. So basically there are two interfaces: one between the hardware and kernel and the other between the kernel and other high level processes. System calls provide the latter interface. System call interacts with the kernel employing a syscall vector. In this vector each system call vector has a fixed position. Note that each version of Unix may individuallydiffer in the way they organize the syscall vector. The fork() is a system call.

An Example of a System Call:

To trace the sequence when a system call to open a file occurs.• User process executes a syscall open a file.• User process links to a c runtime library for open and sets up the neededparameters in registers.• A SW trap is executed now and the operation switches to the kernel mode.- The kernel looks up the syscall vector to call "open"- The kernel tables are modified to open the file.- Return to the point of call with exit status.• Return to the user process with value and status.• The user process may resume now with modified status on file or abort on errorwith exit status.

Page 15: Unix assignment

Q11) Define Zombie State process transition ?

Zombie process is a process in which its child is terminated r gets killed before its termination.It is a process that completes execution but is still in process table.When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process's entry in the process table remains. The parent can read the child's exit status by executing the wait system call, at which stage the zombie is removed.After the zombie is removed, its process ID and entry in the process table can then be reused. However, if a parent fails to call wait, the zombie will be left in the process table. In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same process ID.

Page 16: Unix assignment

Q12)Write a shell script to find the number of ordinary files and directory in the current directory.

num_files=`find . -maxdepth 1 -type f | wc -l`num_directories=`find . -maxdepth 1 -type d | wc -l`num_total=`expr $num_files + $num_directories`echo "The number of ordinary files and directories in the current directory is" $num_total

Page 17: Unix assignment

13Q) What is the first step in booting a UNIX OS?

When the power comes on or the system is reset, the BIOS starts the master boot program, located in the first 512 bytes of the system disk. This program then typically loads the boot program located in the first 512 bytes of the active partition on that disk, which then loads the kernel. Sometimes, the master boot program loads the kernel itself. The boot process from other media is similar.

The firmware program is basically just smart enough to figure out if the hardware devices it needs are accessible (e.g., can it find the system disk or the network) and to load and initiate the boot program. This first-stage boot program often performs additional hardware status verification, checking for the presence of expected system memory and major peripheral devices. Some systems do much more elaborate hardware checks, verifying the status of virtually every device and detecting new ones added since the last boot.

Page 18: Unix assignment

14Q) Explain the details Operating System services?

1)Program Execution

The purpose of a computer systems is to allow the user to execute programs. So the operating systems provides an environment where the user can conveniently run programs. The user does not have to worry about the memory allocation or multitasking or anything. These things are taken care of by the operating systems.

Running a program involves the allocating and deallocating memory, CPU scheduling in case of multiprocess. These functions cannot be given to the user-level programs. So user-level programs cannot help the user to run programs independently without the help from operating systems.

2) I/O Operations

Each program requires an input and produces output. This involves the use of I/O. The operating systems hides the user the details of underlying hardware for the I/O. All the user sees is that the I/O has been performed without any details. So the operating systems by providing I/O makes it convenient for the users to run programs.

For efficiently and protection users cannot control I/O so this service cannot be provided by user-level programs.

3)File System Manipulation

The output of a program may need to be written into new files or input taken from some files. The operating systems provides this

Page 19: Unix assignment

service. The user does not have to worry about secondary storage management. User gives a command for reading or writing to a file and sees his her task accomplished. Thus operating systems makes it easier for user programs to accomplished their task.

This service involves secondary storage management. The speed of I/O that depends on secondary storage management is critical to the speed of many programs and hence I think it is best relegated to the operating systems to manage it than giving individual users the control of it. It is not difficult for the user-level programs to provide these services but for above mentioned reasons it is best if this service s left with operating system.

4)Communications

There are instances where processes need to communicate with each other to exchange information. It may be between processes running on the same computer or running on the different computers. By providing this service the operating system relieves the user of the worry of passing messages between processes. In case where the messages need to be passed to processes on the other computers through a network it can be done by the user programs. The user program may be customized to the specifics of the hardware through which the message transits and provides the service interface to the operating system.

5)Error Detection

Page 20: Unix assignment

An error is one part of the system may cause malfunctioning of the complete system. To avoid such a situation the operating system constantly monitors the system for detecting the errors. This relieves the user of the worry of errors propagating to various part of the system and causing malfunctioning.

This service cannot allowed to be handled by user programs because it involves monitoring and in cases altering area of memory or deallocation of memory for a faulty process. Or may be relinquishing the CPU of a process that goes into an infinite loop. These tasks are too critical to be handed over to the user programs.  A user program if given these privileges can interfere with the correct (normal) operation of the operating systems.

Page 21: Unix assignment

15Q) Explain the details about process states & state Transition?

Process States

1) Created2) Ready to run/runnable3) Running4) Sleeping5) Suspended6) Zombie

Created: When the process is created.

Ready to Run: process is still to be selected by the scheduler .process might be in memory or disk.

Running: process can be running in either of the 2 modes: user or kernel.

Sleeping: When the process is performing I/P operation then it gives up control of CPU and moves to the sleep state. Process is said to be sleep when an event occurs. Kernal wakes up the sleeping process and then process moves to the ready to run state.

Suspended: process might be suspended by pressing Cntrl Z.

Zombie: Zombie process is a process in which its child is terminated r gets killed before its termination.

Page 22: Unix assignment

Process State Transition

An active process is normally in one of the five states in the diagram. The arrows show how the process changes states.

A process is running if the process is assigned to a CPU. A process is removed from the running state by the scheduler if a process with a higher priority becomes runnable. A process is also preempted if a process of equal priority is runnable when the original process consumes its entire time slice.

A process is runnable in memory if the process is in primary memory and ready to run, but is not assigned to a CPU.

A process is sleeping in memory if the process is in primary memory but is waiting for a specific event before continuing execution. For example, a process sleeps while

Page 23: Unix assignment

waiting for an I/O operation to complete, for a locked resource to be unlocked, or for a timer to expire. When the event occurs, a wakeup call is sent to the process. If the reason for its sleep is gone, the process becomes runnable.

When a process' address space has been written to secondary memory, and that process is not waiting for a specific event, the process is runnable and swapped.

If a process is waiting for a specific event and has had its whole address space written to secondary memory, the process is sleeping and swapped.

If a machine does not have enough primary memory to hold all its active processes, that machine must page or swap some address space to secondary memory.

When the system is short of primary memory, the system writes individual pages of some processes to secondary memory but leaves those processes runnable. When a running process, accesses those pages, the process sleeps while the pages are read back into primary memory.

When the system encounters a more serious shortage of primary memory, the system writes all the pages of some processes to secondary memory. The system marks the pages that have been written to secondary memory as swapped. Such processes can only be scheduled when the system scheduler daemon selects these processes to be read back into memory.

Page 24: Unix assignment

Q16)Write a shell script which accepts a number and displays the list of odd numbers below that number.

echo Enter a numberread n

i=1while [ $i -le $n ]; do echo $i i=`expr $i + 2`done

Page 25: Unix assignment

Q18)Write a shell script to accept the name of the directory as command line argument and display the long listing of that directory. By default the HOME directory's contents should be displayed.

if [ "$1" == "" ]; then ls -l $HOMEelse ls -l $1fi

Page 26: Unix assignment

Q19) What does the kernel in buffer read-ahead?

Many disk accesses are sequential. As we will see in Chapter 18, regular files are stored on disk in large groups of adjacent sectors, so that they can be retrieved quickly with few moves of the disk heads. When a program reads or copies a file, it often accesses it sequentially, from the first byte to the last one. Therefore, many adjacent sectors on disk are likely to be fetched when handling a series of a process's read requests on the same file.

Read-ahead consists of reading several adjacent pages of data of a regular file or block device file before they are actually requested. In most cases, read-ahead significantly enhances disk performance, because it lets the disk controller handle fewer commands, each of which refers to a larger chunk of adjacent sectors. Moreover, it improves system responsiveness. A process that is sequentially reading a file does not usually have to wait for the requested data because it is already available in RAM.

However, read-ahead is of no use when an application performs random accesses to files; in this case, it is actually detrimental because it tends to waste space in the page cache with useless information. Therefore, the kernel reducesor stopsread-ahead when it determines that the most recently issued I/O access is not sequential to the previous one

Page 27: Unix assignment

Q20) List out the various status of the buffer.

Statuses of a buffer

Locked/busy or Unlocked/free. Contains valid data. Buffer is dirty. I.e. the data has been modified since it was

read from disc. The buffer is in use by the kernel. A process is waiting for the buffer.

Page 28: Unix assignment

Q22) Define inode and inode cache

An inode is a data structure on a filesystem in UNIX that stores all the information about a file except its name and its actual data. Inode cache cache stores logical metadata information about files (size, access time, etc). It is a linked list that stores the inodes and pointers to all pages that are part of that file and are currently in memory. The inode cache is dedicated for use by UFS.

Page 29: Unix assignment

Q23.) What are the fields of super block?

A superblock is a record of the characteristics of a filesystem:

filesystem size block size the empty and the filled blocks and their respective counts the size and location of the inode tables the disk block map usage information the size of the block groups.

Q25) Write a shell script to accept a number in the command line and display the sum up to that number.

Page 30: Unix assignment

For example, if the number given is 20, then the sum of numbers 1, 2, 3, ..., 20 should be displayed. By default, the sum upto 50 should be displayed.

echo Enter a numberread n

sum=0i=1while [ $i -le $n ]; do sum=`expr $sum + $i` i=`expr $i + 1`doneecho $sum

sum=0i=1for i in `seq 1 $n`; do sum=`expr $sum + $i`doneecho $sum

Q27.) Define Mounting and Unmounting system call and their syntax.

Page 31: Unix assignment

Mount system call:int mount(const char *type, const char *dir, int flags, void *data);The mount() system call grafts a file system object onto the system file tree at the point dir. The argument data describes the file systemobject to be mounted. The argument type tells the kernel how to inter-pret data. The contents of the file system become available through the new mount point dir. Any files in dir at the time of a successful mount are swept under the carpet so to speak, and are unavailable until the file system is unmounted.

Unmount system call:int unmount(const char *dir, int flags);The unmount() system call disassociates the file system from the speci-fied mount point dir.

Q28.) Explain how a file is mounted and unmounted from the file

Page 32: Unix assignment

The contents of the file system become available through the new mount point dir. Any files in dir at the time of a successful mount are swept under the carpet so to speak, and are unavailable until the file system is unmounted.

The unmount() system call disassociates the file system from the speci-fied mount point dir.

Q29)Write a shell script to accept two filenames and check if both exist. If the second filename exists, then the contents of the first filename should be appended

Page 33: Unix assignment

to it. If the second filename does not exist then create a new file with the contents of first file.

echo Enter first filenameread filename1echo Enter second filenameread filename2

if [ -e $filename1 ]; then echo "$filename1 exists!"fi

if [ -e $filename2 ]; then echo "$filename2 exists!"fi

cat $filename1 >> $filename2

Q30).What are the first 3 steps of process states and transition? Define context of the process

Page 34: Unix assignment

An operating system kernel that allows multi-tasking needs processes to have certain states. Names for these states are not standardised, but they have similar functionality.[1]

First, the process is "created" - it is loaded from a secondary storage device (hard disk or CD-ROM...) into main memory. After that the process scheduler assigns it the state "waiting".

While the process is "waiting" it waits for the scheduler to do a so-called context switch and load the process into the processor. The process state then becomes "running", and the processor executes the process instructions.

If a process needs to wait for a resource (wait for user input or file to open ...), it is assigned the "blocked" state. The process state is changed back to "waiting" when the process no longer needs to wait.

Once the process finishes execution, or is terminated by the operating system, it is no longer needed. The process is removed instantly or is moved to the "terminated" state. When removed, it just waits to be removed from main memory.

Q31)What are the different modes for working in vi? Explain other editors apart from vi .

Page 35: Unix assignment

There are three basic modes of vi:

Command mode

This is the default when you enter vi. In command mode, most letters, or short sequences of letters, that you type will be interpreted as commands, without explicitly pressing Enter . If you press Esc when you're in command mode, your terminal will beep at you. This is a very good way to tell when you're in command mode. (So is :set showmode -- see ".exrc Profile and Miscellaneous Commands".)

Insert mode

In insert mode, whatever you type is inserted in the file at the cursor position. Type a (lowercase letter a, for append) to enter insert mode from command mode; press Esc to end insert mode, and return to command mode.

Line mode

Use line mode to enter line oriented commands. To enter line mode from command mode, type a colon ( : ). Your cursor moves to the bottom of the screen, by a colon prompt. Type a line mode command, then press Enter. Any sensible command from the Unix line editor ex will work, and a few are good to know about. These commands are indicated in this handout by a colon in front of the command. Each time you use a line mode command, you must type a colon to enter line mode, then type the

Page 36: Unix assignment

command by the colon prompt at the bottom of the screen, then press Enter when you finish typing the command. (The search commands starting with / and ? work similarly.

Q33)Give different layers of UNIX Architecture.Explain the intended purposes of each.

Page 37: Unix assignment

Kernel Services Layer

The next level provides all the kernel servicesMapping between user requests and device driverActions The user system call is converted to a kernel service call that actually performs the requested service Process creation and termination I/O services File/disk access services Terminal handling services

System Call Interface Layer

The system call interface layer converts a process running in user mode to a protected kernel mode process. This allows the program to invoke protected kernel routines to perform system functions.

Page 38: Unix assignment

User Process Layer

The uppermost layer consists of user processesrunning:ShellsUnix commandsUtility programsUser application programs User processes:Protected from from other users Have no access to Unix kernel routines except through the system call interfaceuCannot directly access kernel memory space

Kernel vs User Space

In addition to the software levels, Unix also features two "rings of protection" from inadvertent programming errors or malicious attacks that might damage other user's processes or the kernel's processes and data structures The inner protected ring is known as kernel spaceThe outer ring is called user space

User Space

User space is the area in memory where user processes are run. This consists of memory starting above the kernel

Page 39: Unix assignment

and includes the rest of available memory. This memory is protected; the system prevents one user from interfering with another Only kernel process can access a user process A process operating in this memory region is saidto be operating in user mode

Kernel Space

Kernel space is the region of memory where all kernel services are provided via kernel processes Any process executing in kernel space is said to be executing in kernel mode Kernel space is a privileged area; the user hasaccess to it only through the system call interface A user does not have direct access to either all machine instructions or devices A kernel process does have direct access to both Also, a kernel process can modify the memory map, an operation frequently required to performprocess scheduling A user process becomes a kernel process when it executes a system call and starts executing kernel code

Data Flow Between Kernel and User Space

Since users and the kernel do not share memory address space, the mechanism for moving data between them is important When a system call is executed, the arguments to the call and the corresponding kernel routine identification are passed from user space to kernel space

Page 40: Unix assignment

q Kernel routine ID is usually passed either via a hardware machine register or via the stack System call arguments are passed in the u area (user area) of the calling process area of a process (user structure and kernelstack) contains information about the process the kernel needs while the process is running Open files, root, current directory, arguments to current system call, and process text, stack, and data segment sizes A pointer to the process table entry containing information for scheduling such as priority User file descriptor table and information about open files Kernel stack for the process (empty when executing in user mode) Remember, user cannot access kernel space but kernel space can access user space

Unix Command Interface and Commands

Unix command interface is a separate program referred to as the shell The shell provides the user interface between the user and the kernel Unix commands and utilities, like the shell, are also separate programs They are part of a Unix distribution, and are considered part of Unix but not part of the kernel

Unix System ServicesUnix provides a number of system services such as systems administration, system reconfiguration, and file system maintenance Other services include customization

Page 41: Unix assignment

of system parameters Rebuilding of kernel with user drivers Creation and definition of user accounts Set up and maintenance of access control parameters for files and peripherals Most services are built into the kernel as system calls

Unix System Calls

System calls provide a programming interface that allows user programs to access kernel functions There are a large number of system calls that perform functions to manage system resources such as memory, disk storage, and peripherals System calls are defined in a run-time library that provides a mapping of the system call interface to the kernel routine(s) that perform the systemFunctions The shell also provides functionality equivalent to many of the system calls