smu bca 5th sem 2011 unix

16

Click here to load reader

Upload: manoj-yadav

Post on 12-Sep-2014

28 views

Category:

Documents


4 download

DESCRIPTION

Sikkim Manipal University BCA 5th sem 2011 Assignment. 2nd Assignment Question Number 4 part 2 and 3 not done.

TRANSCRIPT

Page 1: SMU BCA 5th sem 2011 Unix

February 2011Bachelor of Computer Application (BCA) – Semester 5

BC0056 – Unix Operating System – 4 Credits (Book ID: B0973)Assignment Set – 1 (40 Marks)

Ques1. Explain UNIX system architecture.

Ans. At the center of the UNIX onion is program called the kernel. It is absolutely crucial to the operation of the UNIX system. The kernel provides the essential services that make up the heart of UNIX system; it allocates memory, keeps track of the physical location of files on the computer’s hard disks, loads, and executes binary programs such as shells, and schedules the task swapping without which UNIX systems would be incapable of doing more than one thing at a time.

Architecture of the UNIX operating system

The kernel accomplishes all these tasks by providing an interface between the other programs running under its control and the physical hardware of the computer; this interface, the system call interface, effectively insulates the other programs on the UNIX system from the complexities of the computer. For example, when a running program needs access to file, it cannot simply open the file. The kernel takes over and handles the request, then notifies the program whether the request succeeded or failed. The kernel determines whether or not the request is valid, and if it is, the kernel reads the required block of data and passes it back to the programs do not have access to the physical hardware of the computer. All they see are the kernel services, provided by the system call interface.Although there is a well-defined, technical and commercial standard for what constitutes “Unix,” in common usage, Unix refers to a set of operating systems, from private vendors and in various open-

Page 2: SMU BCA 5th sem 2011 Unix

licensed versions, that act similarly from the view of users and administrators. Within any Unix version, there are several different “shells” which affect how commands are interpreted. Your default is that you are using Solaris (developed by Sun Microsystems primarily for use on hardware sold by Sun) within the “c-shell.” Most of the basic commands here will work the same in other Unix variants and shells, including Linux and the Mac OS X command-line environment.

A standard Unix system provides command for username, passwd, chsh and additional option on chdgrp to change username, passwords, default group, and shell environments.Wildcard: * is a “wildcard” character that can refer to any character string and ? is a wildcard character that can refer to any single character. For example, mv *.95 code would move every Fortran 95 program file on the current directory into a subdirectory called code.

Filenames: Filenames may be upto 255 characters, and they may include any character except the regular slash /. (Avoid using backslashes, blank spaces, or nonprinting characters in filenames – they are allowed but will cause problems for you.)

A pathnames beginning with / is an absolute path from the top of the system tree. A pathname not beginning with / is a relative path down from the current working directory.

Directory shortcuts include: as a replacement for your home directory, username as a shorthand for username’s home directory, .. (two periods) for the subdirectory on level up from the current directory, and . (one period) for the current directory.

Ques2. What are the various standards in UNIX? Discuss various features of UNIX.

Ans. Because of the multiple version of UNIX and frequent cross-pollination between variants, many features have diverged in the different version of UNIX. With the increasing popularity of UNIX in the commercial and government sector, came the desire to standardize of UNIX so that a user or developer using UNIX could depend on those features.

The institute of Electrical and Electronic Engineers created a series of standards committees to create standards for “An industry-Recognized Operating Systems Interface Standard based on the UNIX Operating System.” The results of two of the committees are important for the general user and developer. The POSIX.1 committee standardizes the C library interface used to write programs for UNIX. In Europe, the X/Open Consortium brings together various UNIX-related standards, including the current attempt at a Common Open System Environment (COSE) specification. X/Open publishes a series of specifications called the X/Open Portability Guide, Currently at version 4.XPG4 is a popular specification in Europe, and many companies in the United States supply version of UNIX that meet XPG.

The United States government has specified a series of standards based on XPG and POSIX. Currently FIPS 151-2 specifies the open system requirements for purchases.

Various Features of UNIX:

Page 3: SMU BCA 5th sem 2011 Unix

multi-usermore than one user can use the machine at a timesupported via terminals (serial or network connection)

multi-taskingmore than one program can be run at a time

hierarchical directory structureto support the organisation and maintenance of files

portabilityonly the kernel ( <10%) written in assemblertools for program developmenta wide range of support tools (debuggers, compilers)

Multi-User Operating SystemsA multi-user operating system allows more than one user to share the same computer system at the same time. It does this by time-slicing the computer processor at regular intervals between the various users.

In the above example, there are five users which share the processor hardware and main memory on a time basis.

Multi-Tasking OperatingSystemsMulti-tasking operating systems permit the use of more than one program to run at once. It does this in the same way as a multi-user system, by rapidly switching the processor between the various programs.

OS/2 and Windows 95 are examples of multi-tasking single-user operating system. UNIX is an example of a multi-tasking multi-user operating system.

Page 4: SMU BCA 5th sem 2011 Unix

A multi-user system is also a multi-tasking system. This means that a user can run more than one program at once, using key selection to switch between them.

Multi-tasking systems support foreground and background tasks. A foreground task is one that the user interacts directly with using the keyboard and screen. A background task is one that runs in the background (it does not have access to the keyboard). Background tasks are usually used for printing or backups.

The role of the operating system is to keep track of all the programs, allocating resources like disks, memory and printer queues as required.

Ques3. What are various File Systems supported in UNIX? Discuss any three of them.

Ans. Root

This file system must be present in every UNIX system. It contains the barebones UNIX-the root directory, /bin/usr/bin,/etc,/sbin,/usr/sbin,/dev and /lib directories all the tools and utilities that are just adequate to keep the system is booted in single-user mode, this is the only file system going.

When the system is booted in single-user mode, this is the only file system available to the system administrator.

Swap

Every system should have a swap file system which is used by the kernel to movement of processes. When the system memory is heavily loaded, the kernel has to move process. When the system memory is heavily loaded, the kernel has to move process out of memory to this file system. When these swapped processes are ready to run, they are loaded back to memory. Users can’t access data in this file system directly.

A UNIX system contains many more file systems. System files should be kept separate from data files created by users, and hence a separate file system is usually made for them. Linux and SVR4 create user’s home directories in/home, but older systems use/usr./home is often maintained as a separate file system. If there’s no space left on/home, the administrator uses other file systems like/user2 or /u. You can have additional file systems for /tmp and /var/tmp so that temporary and log files can’t grow indefinitely.

File System Types

Initially, there were only two types of file systems-the ones from AT&T and Berkeley. Following are some file systems types:

s5

Before SVR4, this was the only file system used by System V, but today it is offered by SVR4 by this name for backward compatibility only. This file system uses a logical block size of 512 or 1024 bytes and a single super block. It also can’t handle filenames longer than 14 characters.

Page 5: SMU BCA 5th sem 2011 Unix

ufs

This is how the Berkeley fast file systems is known to SVR4 and adopted by most UNIX systems. Because the block size here can go up to 64 KB, performance of this file system is considerably better than s5. It uses multiple super blocks with each cylinder group storing a superblock. Unlike s5, ufs supports 255-character filenames, symbolic links and disk quotas.

Fdisk

Creating Partitions

Both Linux and SCO UNIX allow a user to have multiple operating systems on Intel Machines. It’s no wonder then that both offer the Windows-type fdisk command to create, delete and activate partitions. fdisk in Linux , however, operates differently from windows. The fdisk m command shows you all its internal commands of which the following subset should serve our purpose:

Command Action

A toggle a bootable flag N add a new partition

D delete a partition P Print partition table

L list known partition types Q Quit without saving

M print this menu W Write table to disk & exit.

mkfs : creating file systems

Now that you have created a partition, you need to create a file system on this partition to make it usable. mkfs is used to build a Linux file system on a device, usually a hard disk partition. The exit code returned by mkfs is 0 on success and 1 on failure.

The file system-specific builder is searched for in a number of directories like perhaps /sbin, /sbin/fs, /sbin/fs.d, /etc/fs, /etc (the precise list is defined at compile time but at least contains /sbin and /sbin/fs), and finally in the directories listed in the PATH enviroment variable.

Ques4. What do you mean by a Process? What are the various possible states of Process? Discuss.

Ans. A process under Unix consists of an address space and a set of data structures in the kernel to keep track of that process. The address space is a section of memory that contains the code to execute as well as the process stack. The kernel must keep track of the following data for each proc ess on the system:

Page 6: SMU BCA 5th sem 2011 Unix

The address space map,The current status of the process,The execution priority of the process,The resource usage of the process,The current signal mask,The owner of the process,

A process has certain attributes that directly affect execution, these include:

PID – The PID stands for the process identification. This is a unique number that defines the process within the kernel.

PPID – This is the processes Parent PID, the creator of the process.

UID – This User ID number of the user that owns this process.

EUID – The effective User ID of the process.

GID – The Group ID of the user that owns this process.

EGID – The effective Group User id that owns this process.

Priority – The priority that this process runs at.

To view a process you use the ps command.

# ps –l

F S UID PID PPID C PRI NI P SZ:RSS WCHAN TTY TIME COMD

30 S 0 11660 145 1 26 20 * 66:20 88249f10 ttyq 6 0:00 rlogind

The F field: This is the flag field. It uses hexadecimal values which are added to show the value of the flag bits for the process. For a normal user process this will 30, meaning it is loaded into memory.

The S field: The S field is the state of the process, the two most common values are S for Sleeping and R for Running. An im portant value to look for is X which means the process is waiting for memory to become available.

PID Field: The PID shows the process ID of each process. This Value should be Unique. Generally PID are allocated lowest to highest, but wrap at some point. This value is necessary for you to send a signal to a process such as the kill signal.

Page 7: SMU BCA 5th sem 2011 Unix

PRI field: This stand for priority field. The process with the lowest value in the ‘PRi’ field which has the highest priority. The lower the value, the higher the value. This refer to the process NICE value. It will range form 0 to 39. The default is 20, as a process uses the CPU the system will raise the nice value.

P flag: this is the processor flag. On the SGI this refers to the processor the process is running on.

SZ field: This refers to the SIZE field. This is the total number of pages in the process. Each page is 4096 bytes.

TTY field: this the terminal assigned to your process.

Time field: the Cumulative execution time of the process in minutes and seconds.

COMD field: the command that wat executed.

Ques5. With proper syntax explain the use of chmod command.

Ans. File and directory permissions can only be modified by their owners, or by the superuser (root), by using the chmod system utility.

chmod (change [file or directory] mode) $ chmod options files

chmod accepts options in two forms. Firstly, permissions may be specified as a sequence of 3 octal digits (octal is like decimal except that the digit range is 0 to 7 instead of 0 to 9). Each octal digit represents the access permissions for the user/owner, group and others respectively. The mappings of permissions onto their corresponding octal digits is as follows:

--- 0 --x 1 -w- 2 -wx 3 r-- 4 r-x 5 rw- 6 rwx 7

For example the command: $ chmod 600 private.txt

sets the permissions on private.txt to rw------- (i.e. only the owner can read and write to the file). Permissions may be specified symbolically, using the symbols u (user), g (group), o (other), a (all), r (read), w (write), x (execute), + (add permission), – (take away permission) and = (assign permission). For example, the command:

$ chmod ug=rw,o-rw,a-x *.txt

Page 8: SMU BCA 5th sem 2011 Unix

sets the permissions on all files ending in *.txt to rw-rw---- (i.e. the owner and users in the file's group can read and write to the file, while the general public do not have any sort of access). chmod also supports a -R option which can be used to recursively modify file permissions, e.g.

$ chmod -R go+r play

will grant group and other read rights to the directory play and all of the files and directories within play.

chgrp (change group)

$ chgrp group files can be used to change the group that a file or directory belongs to. It also supports a -R option.

Page 9: SMU BCA 5th sem 2011 Unix

February 2011Bachelor of Computer Application (BCA) – Semester 5

BC0056 – Unix Operating System – 4 Credits Assignment Set – 2 (40 Marks)

Ques1. Explain the significance of option –I, -v with grep command

Ans. grep (General Regular Expression Print)

$ grep options pattern files

grep searches the named files (or standard input if no files are named) for lines that match a given pattern. The default behavior of grep is to print out the matching lines. For example:

$ grep hello *.txt searches all text files in the current directory for lines containing "hello". options that grep provides are:

-i (Displays list of filenames only)-v (print out the lines that don't match the pattern)

$ grep -vi hello *.txt

searches all text files in the current directory for lines that do not contain any form of the word hello (e.g. Hello, HELLO, or hELlO).

Ques2. Write a simple command and show how a process can be suspended.

Ans.

kill (terminate or signal a process) It is sometimes necessary to kill a process (for example, when an executing program is in an infinite loop) To kill a job running in the foreground, type ^C (control c). For example, run

$ sleep 100 ^C

To kill a suspended or background process, type

$ kill $jobnumber

For example, run

$ sleep 100 & $ jobs

Page 10: SMU BCA 5th sem 2011 Unix

If it is job number 4, type

$ kill $4

To check whether this has worked, examine the job list again to see if the process has been removed. ps (process status) Alternatively, processes can be killed by finding their process numbers (PIDs) and using kill PID_number $ sleep 100 & $ ps

PID TT S TIME COMMAND 20077 pts/5 S 0:05 sleep 100 21563 pts/5 T 0:00 netscape 21873 pts/5 S 0:25 nedit

To kill off the process sleep 100, type $ kill 20077

and then type ps again to see if it has been removed from the list. If a process refuses to be killed, uses the -9 option, i.e. type $ kill -9 20077

Ques3. Mention few services provided by UUCP with one example.

Ans.

UUCP

UUCP (Unix - Unix Copy) Command helps you to use directly to send and receive files. UUCP is designed for use with standard serial cables, modems and telephone service. There are some essential requirements before you can use UIUCP. First there must be a physical link between two UUCP computers. Second, UUCP must be installed on both the local and remote sites. UUCP is based on store and forward system.

UUCP Applications

UUCP provides several services. i) Exchanging mails

ii) Determining your local node name

iii) Executing commands on a remote Unix system with the UUX command and non-UUCP, CU and tip commands.

iv) Transferring files between Unix sites using uuto uupick and UUCP.

An address for sending e-mail via UUCP that specifies the entire route to the destination computer. It separates each host name with an exclamation point, which is known as a bang.

Page 11: SMU BCA 5th sem 2011 Unix

For example, the bang path midearth!shire!bilbo!jsmith would go to the JSMITH user account on the BILBO host, which is reached by first going to MIDEARTH and then SHIRE.

Ques4. How will you perform the following in vi? i) To search and replace all occurences of pattern1 with pattern2

ii) insert text (and enter input mode)

iii) append text (to end of line)

iv) Move to beginning of line

v) Move to the end of line

Ans. i) To search and replace all occurences of pattern1 with pattern2, type :

%s/pattern1/pattern2/g.

To be asked to confirm each replacement, add a c to this substitution command. Instead of the % you can also give a range of lines (e.g. 1,17) over which you want the substitution to apply.

ii)

iii)

iv) Use these Command mode keystrokes to move around within the file:

0 Move to the beginning of the current line.

v) Use these Command mode Keystrokes to move around within the file$ Move to the end of the current line

Ques5. What is a crond? What is its use?

Ans. crond is a daemon that executes commands that need to be run regularly according to some schedule. The schedule and corresponding commands are stored in the file /etc/crontab. Each entry in the /etc/crontab file entry contains six fields separated by spaces or tabs in the following form: minute hour day_of_month month weekday command These fields accept the following values: minute 0 through 59 hour 0 through 23 day_of_month 1 through 31 month 1 through 12 weekday 0 (Sun) through 6 (Sat) command a shell command You must specify a value for each field. Except for the command field, these fields can contain the following:

A number in the specified range, e.g. to run a command in May, specify 5 in the month field.

Page 12: SMU BCA 5th sem 2011 Unix

Two numbers separated by a dash to indicate an inclusive range, e.g. to run a cron job on Tuesday through Friday, place 2-5 in the weekday field.

A list of numbers separated by commas, e.g. to run a command on the first and last day of January, you would specify 1,31 in the day_of_month field.

* (asterisk), meaning all allowed values, e.g. to run a job every hour, specify an asterisk in the hour field.

You can also specify some execution environment options at the top of the /etc/crontab file: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root To run the calendar command at 6:30am. every Mon, Wed, and Fri, a suitable /etc/crontab entry would be: 30 6 * * 1,3,5 /usr/bin/calendar The output of the command will be mailed to the user specified in the MAILTO environment option. You don't need to restart the cron daemon crond after changing /etc/crontab - it automatically detects changes.