Você está na página 1de 15

1

Name: Registration No: Learning Centre: Learning Centre Code: Course: Applications (BCA) Subject: Semester: Module No: Date of Submission: Marks Awarded:

Bhawani Pratap Singh 520840181 Atmark Infotech 01669 Bachelor of Computer BC0056 UNIX Operating System 5th Semester I 20 November 2010

Signature of Signature of Coordinator Evaluator

Signature of Centre head

August 2010 Bachelor of Computer Application (BCA) Semester 5 BC0056 UNIX Operating System
(Book ID: B0973)

4 Credits

Assignment Set 1 (40 Marks)

Each question carries eight marks 1. What are the layers present in UNIX Architecture? List and explain each of them.

Answer Architecture of UNIX UNIX System Kernel Three major tasks of kernel: Process Management Device Management File Management Three additional Services for Kernel: Virtual Memory Networking Network File Systems Experimental Kernel Features: Multiprocessor support Lightweight process (thread) support

The layers of UNIX


Other applications Standard application

W C

gre p

Standard libraries

fopen()
File system Hardware

fork()

Process control

Process Control Subsystem Process Synchronization Interprocess communication Memory management: Scheduler: process scheduling (allocate CPU to Processes)

File system A file system is a collection of files and directories on a disk or tape in standard UNIX file system format. Kernels file system regulates data flow between the kernel and secondary storage devices.

System Call for

4 1. Process Control: fork: create a new process wait: allow a parent process to synchronize its execution with the exit of a child process. exec: invoke a new program. exit: terminate process execution 2. File system: File: open, read, write, lseek, close inode: chdir, chown chmod, stat fstat others: pipe dup, mount, unmount, link, unlink System call: fork() fork: the only way for a user to create a process in Unix operating system. The process that invokes fork is called parent process and the newly created process is called child process. The syntax of fork system call: newpid = fork(); On return from fork system call, the two processes have identical copies of their userlevel context except for the return value pid. In parent process, newpid = child process id In child process, newpid = 0.

2. What is the significance of root and swap? Discuss their uses and charatertistics.

Answer Most UNIX systems spilt a disk into as many as 8 partitions. If there are multiple disks, every such disk should have at least one file system on it. In general, most UNIX has two file systems: Root file system It contains 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 booted in single user mode. When

5 the system is booted in single user mode, this is the only file system available to the system administrator. In computer file systems, the root directory is the first or top-most directory in a hierarchy. It must be present in every UNIX system. It can be likened to the root of a tree the starting point where all branches originate. Metaphor To use the example of a physical file cabinet, if the separate drawers in the file cabinet are represented as the highest level of sub-directories in the file system or system prompt, then the room the file cabinet is in, may be represented as the root directory. That is, the other directories may be inside it, but the root directory cannot go in any other directories, at least in that file system. In most operating systems, files can be placed inside the root directory, as well in its sub-directories. One may envision this as placing paper files anywhere in the room, or into any file cabinet within the room. Multiple root directories UNIX abstracts the nature of this tree hierarchy entirely, and in Unix and Unix-like systems, the root directory is denoted /. Though the root directory is conventionally referred to as /, the directory entry itself has no name its name is the "empty" part before the initial directory separator character (/). All filesystem entries, including mounted partitions are "branches" of this root. In UNIX-like operating systems, each process has its own idea of what the root directory is. For most processes this is the same as the system's actual root directory, but it can be changed by calling the chroot system call. This is typically done for security purposes to restrict which files a process may access to just a subset of the file hierarchy. Root On many Unixes, there is also a directory which is named root. Confusingly, it is not a root directory in the sense of this article, but rather the home directory of the Superuser (conventionally known as "root"). Swapping in Unix In computer operating systems, paging is one of the memory-management schemes by which a computer can store and retrieve data from secondary storage for use in main memory. In the paging memory-management scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. The main advantage of paging is that it allows the physical address space of a process to be noncontiguous. Before paging, systems had to fit

6 whole programs into storage contiguously, which caused various storage and fragmentation problems. Paging is an important part of virtual memory implementation in most contemporary generalpurpose operating systems, allowing them to use disk storage for data that does not fit into physical Random-access memory (RAM). Paging is usually implemented as architecturespecific code built into the kernel of the operating system. The main functions of paging are performed when a program tries to access pages that are not currently mapped to physical memory (RAM). This situation is known as a page fault. The operating system must then take control and handle the page fault, in a manner invisible to the program. Therefore, the operating system must: 1. 2. 3. 4. 5. Determine the location of the data in auxiliary storage. Obtain an empty page frame in RAM to use as a container for the data. Load the requested data into the available page frame. Update the page table to show the new data. Return control to the program, transparently retrying the instruction that caused the page fault. Because RAM is faster than auxiliary storage, paging is avoided until there is not enough RAM to store all the data needed. When this occurs, a page in RAM is moved to auxiliary storage, freeing up space in RAM for use. Thereafter, whenever the page in secondary storage is needed, a page in RAM is saved to auxiliary storage so that the requested page can then be loaded into the space left behind by the old page. Efficient paging systems must determine the page to swap by choosing one that is least likely to be needed within a short time. There are various page replacement algorithms that try to do this. Most operating systems use some approximation of the least recently used (LRU) page replacement algorithm (the LRU itself cannot be implemented on the current hardware) or working set based algorithm. If a page in RAM is modified (i.e. if the page becomes dirty) and then chosen to be swapped, it must either be written to auxiliary storage, or simply discarded. To further increase responsiveness, paging systems may employ various strategies to predict what pages will be needed soon so that it can preemptively load them. Swap prefetch A few operating systems use anticipatory paging, also called swap prefetch. These operating systems periodically attempt to guess which pages will soon be needed, and start loading them

7 into RAM. There are various heuristics in use, such as "if a program references one virtual address which causes a page fault, perhaps the next few pages' worth of virtual address space will soon be used" and "if one big program just finished execution, leaving lots of free RAM, perhaps the user will return to using some of the programs that were recently paged out". Paging sometimes referred to a memory allocation scheme that used fixed-length pages as opposed to variable-length segments, without implicit suggestion that virtual memory technique were employed at all or that those pages were transferred to disk. Such usage is rare today. Some modern systems use the term swapping along with paging. Historically, swapping referred to moving from/to secondary storage a whole program at a time, in a scheme known as roll-in/roll-out. In the 1960s, after the concept of virtual memory was introducedin two variants, either using segments or pagesthe term swapping was applied to moving, respectively, either segments or pages, between disk and memory. Today with the virtual memory mostly based on pages, not segments, swapping became a fairly close synonym of paging, although with one difference. In many popular systems, there is a concept known as page cache, of using the same single mechanism for both virtual memory and disk caching. A page may be then transferred to or from any ordinary disk file, not necessarily a dedicated space. Page in is transferring a page from the disk to RAM. Page out is transferring a page from RAM to the disk. Swap in and out only refer to transferring pages between RAM and dedicated swap space or swap file, and not any other place on disk.

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

Answer

A process is a collection of interrelated work or tasks initiated in response to an event that achieves a specific result for the customer of the process. In general, a UNIX process is one execution of a program or command. Every process transforms one or more input streams into one or more output streams. Whenever you type a UNIX command, you are creating a process to carry out the work of that command. In a multitasking computer system, processes may occupy a variety of states. These distinct states may not actually be recognized as such by the operating system kernel; however they are a useful abstraction for the understanding of processes. Created (Also called New) When a process is first created, it occupies the "created" or "new" state. In this state, the process awaits admission to the "ready" state. This admission will be approved or delayed by a long-term, or admission scheduler. Typically in most desktop computer systems, this admission will be approved automatically, however for real-time operating systems this admission may be delayed. In a real time system, admitting too many processes to the "ready" state may lead to over saturation and over contention for the systems resources, leading to an inability to meet process deadlines. Ready or waiting(Also called waiting or runnable) A "ready" or "waiting" process has been loaded into main memory and is awaiting execution on a CPU (to be context switched onto the CPU by the dispatcher, or short-term scheduler). There may be many "ready" processes at any one point of the systems execution. Example : in a one processor system, only one process can be executing at any one time, and all other "concurrently executing" processes will be waiting for execution. A ready queue or run queue is used in computer scheduling. Modern computers are capable of running many different programs or processes at the same time. However, the CPU is only capable of handling one process at a time. Processes that are ready for the CPU are kept in a queue for "ready" processes. Other processes that are waiting for an event to occur, such as

9 loading information from a hard drive or waiting on an internet connection, are not in the ready queue. Running A process moves into the running state when it is chosen for execution by the CPU. The process's instructions are executed by one of the CPUs (or cores) of the system. There is at most one running process per CPU or core. Blocked A process that is blocked on some event such as I/O operation completion or a signal is blocked and kept in a blocked state; CPUs cannot select any processes from this state. Once the event for which they were waiting occurs, the process is moved to the ready state. Terminated A process may be terminated, either from the "running" state by completing its execution or by explicitly being killed. In either of these cases, the process moves to the "terminated" state. If a process is not removed from memory after entering this state, the process will be called a zombie. Additional process states Two additional states are available for processes in systems that support virtual memory. In both of these states, processes are "stored" on secondary memory (typically a hard disk). Swapped out and waiting (Also called suspended and waiting) In systems that support virtual memory, a process may be swapped out, that is removed from main memory and placed in virtual memory by the mid-term scheduler. From here the process may be swapped back into the waiting state. Swapped out and blocked (Also called suspended and blocked) Processes that are blocked may also be swapped out. In this event the process is both swapped out and blocked, and may be swapped back in again under the same circumstances as a swapped out and waiting process, although in this case, the process will move to the blocked state, and may still be waiting for a resource to become available).

4. What is the purpose of setting accounts in Unix ? Explain the concept of privileges and its significance.

Answer Purpose of setting accounts in UNIX

10 Consider there is a user user1 then: For security- every user needs to have an account, which includes user name and password. This also indicates who owns the files and directories on the system and what groups the users may belong to. A system administrator is responsible for creating, modifying and deleting user accounts. When a user account is created, an entry is made in the /etc/passwd file. When a group account is created, an entry is made in the /etc/group file. The user name is a unique name that identifies the user1 to the system. The system administrator will make sure that no one has the same user name before allowing user1 to have it. The password assigned is temporary and it can be changed by user1 afterwards. To start a UNIX system, users are expected to log on to the system. The system prompts asks to enter the user name and password. After entering the correct information and if the system administrator is set up correctly, the user can now use the system. If incorrect username and password has been entered then again the user will be asked to enter the information, this goes till a user enters correct information. Privileges On many computer operating systems, the super user, or root, is a special user account used for system administration. This account should be used to do system wide administrative account. It is important to be careful when using this account because it has special features. Most users cannot set up a new user account nor do other administrative procedures. The super-user can do anything on the system. For this reason every user must have their own user account, which does not have root privilege. By this, their personal activities will affect only their environment and will be in no danger of causing system wide problems. Separation of administrative privileges from normal user privileges makes an operating system more resistant to viruses and other malware. Additionally, in organizations, administrative privileges are often reserved for authorized individuals in order to control abuse, misuse, or other undesired activities by end-users. In a multiuser, non-personal environment, most likely there is an only one user privilege. This security is even more important when more than one person is involved because one mistake by the root can affect every user and the entire system. UNIX also has security to help prevent different users from harming each other on a multiuser system. Each user has a personal environment and can selectively let groups to access their works. While working in a team and the user wants his work to be shared by many people on the system, then the user should allow access to everyone.

5. What are the uses of Erase, Kill and eof commands in UNIX? Discuss.

11 Answer Different control characters are present in UNIX, some are erase, kill and eof. To see their values or control associated to them types stty command. Erase On a system, erase which means to back up over the last character typed, done by typing ^H. The erase key helps us to correct our typing errors. To erase any character using erase, first type the character, say x, then press ^H (control H) to erase it. If everything is done correcting then the cursor should have backed up to be on top of x and the next key will be displayed where x was present. If ^H is not working for erase then we can set our own value for it by using $ stty command. To set a key for erase $stty erase ^H or any other value of the users choice. The erase key is one of the most used control keys, because typing without mistakes is difficult to do. Therefore, most keyboards have one or more special keys that are suited to this job. Either delete or backspace always works as an erase key. Kill The kill control is similar to the erase control character, in the it allows the user to back up over typing mistakes. Whereas erase backs up one character at a time, kill backs up all the way to the prompt. Therefore, if the user is typing a really long command and realize, toward the end, that he forgot to do some other command first. In this case the user can start over by typing the control character associated with kill. Normally kill command is set to ^X, but it can be changed according to users convenience. After using kill command all the lines typed by the user will be erased and cursor will be present just after the prompt. Eof (end of file) The eof control character is used to signal the end of output. The letters eof come from end of file. The normal value of the eof control character is ^D, but should be verified by using the stty command. The stty command is also used to set the value of control characters.

12

Name: Registration No: Learning Centre: Learning Centre Code: Course: Applications (BCA) Subject: Semester: Module No: Date of Submission: Marks Awarded:

Bhawani Pratap Singh 520840181 Atmark Infotech 01669 Bachelor of Computer BC0056 UNIX Operating System 5th Semester II 20 November 2010

13

Signature of Signature of Coordinator Evaluator

Signature of Centre head

August 2010 Bachelor of Computer Application (BCA) Semester 5 BC0056 UNIX Operating System
(Book ID: B0973)

4 Credits

Assignment Set 2 (40 Marks)

Each question carries eight marks 1. Explain the significance of option I, -v with grep command?

2. Describe the various compression activities.

utilities

used

for

taking

back-up

and

Answer File compression and backup UNIX systems usually support a number of utilities for backing up and compressing files. The most useful are tar (tape archiver) tar backs up entire directories and files onto a tape device or into a single disk file known as an archiver. An archiver is a file that contains other files plus

14 information about them, such as their filename, owner, timestamps and access permissions. tar does not perform any compression by default. To create a disk file tar archive use $ tar cvf archivenamefilename Where archivenamefilename will usuallyhave a .tar extension. c option means create, v means verbose (o/p filenames as they are archived) and f means file. To list the content of a tar archive we use, $ tar tvf archivename To restore files from a tar archive, $ tar xvf archivename cpio cpio is another facility for creating and reading archives. Unlike tar, cpio doesnt automatically archive the contents of directories, so its common to combine cpio with find when creating an archive: $ find print depth |cpio ov Htar >archivename This will take all the files in the current directory and all directories below and place them in an archive called archivename. The depth option controls the order in which the filenames are produced and is recommended to prevent problems with directory permissions when doing a restore. The o option creates the archive, the v option prints the names of the files archived as they are added and the H option specifies an archive format type, in this case it creates a tar archive. Another common archive type is crc, a portable format with a checksum for error control. To list the contents of a cpio archive use, $ cpio tv < archivename To restore $ cpio idv < archivename. The d option will create directories as necessary. To force cpio to extract files on top of files of the same name that already exists. Compress, gzip compress and gzip are utilities for compressing and decompressing individual files which may or may not be archive files. To compress file, .$ compress filename. Or .$ gzip filename. In each case, filename will be deleted and replaced by a compressed file called filename.Z or filename.gz. The reverse the compression process, $ compress d filename or $ gzip filename.

3. Explain with an example the use of redirection input and output.

4. Write a shell script to display the sum of n numbers.

15

5. How do you perform the following in emacs? i. ii. iii. Delete character under cursor Delete word Delete to end of line(s)

Você também pode gostar