free bca sem5 unix 2014 .docx

6
 Student Name: Savin Sadanand Shetty Course: BCA Registration Number: 571016956 LC Code: Subj ect Name: UNIX OPERATING SYS TE Subje ct Code: BC0056 Q1) Explain the Layers of UNIX OS in detail. Ans. The UNIX operating system is a set of programs that act as a link between the computer and the user. The computer program that allocates the system resources and coordinates all the details of the computer's internal is called the operating system or kernel. Users communicate with the kernel through a program known as the shell. The shell is a command line interpreter; it translates commands entered by the user and converts them into a language that is understood by the kernel. Unix was originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. There are various Unix variants available in the market. Solaris UNIX, AIX, UP Unix and BSD are few examples. Linux is also a flavour of Unix which is freely available. Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system. A user can also run multiple programs at the same time; hence UNIX is called multitasking. Unix Architecture: The main concept that unites all versions of UNIX is the following four basics: Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of the tasks like memory management, tash scheduling and file management. Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are most famous shells which are available with most of the Unix variants. Commands and Utilities:  There are various command and utilities which you would use in your day to day activities. cp, mv, cat and grep etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various optional options. Files and Directories: All data in UNIX is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the file system. Q2) Write a short note on a. The fork() System Call

Upload: savin-shetty

Post on 13-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 1/6

  Student Name: Savin Sadanand Shetty Course: BCA

Registration Number: 571016956 LC Code:

Subject Name: UNIX OPERATING SYSTE Subject Code: BC0056

Q1) Explain the Layers of UNIX OS in detail.Ans. The UNIX operating system is a set of programs that act as a link between the computer and the user. Thecomputer program that allocates the system resources and coordinates all the details of the computer's internal is called

the operating system or kernel. Users communicate with the kernel through a program known as the shell. The shell is a

command line interpreter; it translates commands entered by the user and converts them into a language that isunderstood by the kernel.

Unix was originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, DennisRitchie, Douglas McIlroy, and Joe Ossanna.

There are various Unix variants available in the market. Solaris UNIX, AIX, UP Unix and BSD are few examples.Linux is also a flavour of Unix which is freely available.

Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system.

A user can also run multiple programs at the same time; hence UNIX is called multitasking.

Unix Architecture: 

The main concept that unites all versions of UNIX is the following four basics:

Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of the tasks like memory

management, tash scheduling and file management.

Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interpretsthe command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne

Shell and Korn Shell are most famous shells which are available with most of the Unix variants.

Commands and Utilities: There are various command and utilities which you would use in your day to day activities.cp, mv, cat and grep etc. are few examples of commands and utilities. There are over 250 standard commands plus

numerous others provided through 3rd party software. All the commands come along with various optional options.

Files and Directories: All data in UNIX is organized into files. All files are organized into directories. These directories are organized into atree-like structure called the file system.

Q2) Write a short note ona. The fork() System Call

Page 2: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 2/6

 b. The pipe() System Call

Ans. A. The Fork() System CallTo create a new process, in UNIX, the fork() system call is used. Fork() creates a new context based on the context ofthe calling process. The fork() call is unusual in that it returns twice: It returns in both the process calling fork() and inthe newly created process. The child process returns zero and the parent process returns a number greater then zero.

The synopsis for fork() is as follows:

#include

 pid_t fork(void);

 pid_t vfork(void);

If fork() is successful, it returns a number of type pid_t which is greater than 0 and represents the PID of the newlycreated child process. In the child process, fork() returns 0. If fork() fails then its return value will be less than 0.vfork() is a m ore efficient version of fork(), which does not duplicate the entire parent context.

B. The pipe() System CallThe pipe() function creates a pipe, which is an object allowing bidirectional data flow, and allocates a pair of file

descriptors. By convention, the first descriptor is normally used as the read end of the pipe, and the second is normallythe write end, so that data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one program to be sent to another program: the source's standard output is set up to be the write end of the pipe, and thesink's standard input is set up to be the read end of the pipe. The pipe itself persists until all its associated descriptorsare closed.A pipe that has had an end closed is considered widowed. Writing on such a pipe causes the writing processto receive a SIGPIPE signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the readerconsumes any buffered data, reading a widowed pipe returns a zero count. The bidirectional nature of thisimplementation of pipes is not portable to older systems, so it is recommended to use the convention for using theendpoints in the traditional manner when using a pipe in one direction.

Q 3) What are the points to be considered for the management of a password in UNIX OS?Ans. There are three types of accounts on a Unix system:

Page 3: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 3/6

 Root account: This is also called superuser and would have complete and unfettered control of the system. A superusercan run any commands without any restriction. This user should be assumed as a system administrator.

System accounts: System accounts are those needed for the operation of system-specific components for example mailaccounts and the sshd accounts. These accounts are usually needed for some specific function on your system, and anymodifications to them could adversely affect the system.

User accounts: User accounts provide interactive access to the system for users and groups of users. General users are

typically assigned to these accounts and usually have limited access to critical system files and directories.

Unix supports a concept of Group Account which logically groups a number of accounts. Every account would be a part of any group account. Unix groups plays important role in handling file permissions and process management.

Managing Users and Groups:There are three main user administration files:

/etc/passwd: Keeps user account and password information. This file holds the majority of information about accountson the Unix system.

/etc/shadow: Holds the encrypted password of the corresponding account. Not all the system support this file.

/etc/group: This file contains the group information for each account.

/etc/gshadow: This file contains secure group account information.

Q 4) What is a Process? How to run a process at the background?

Page 4: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 4/6

Ans. A process is a program in execution in memory or in other words, an instance of a program in memory. Any program executed creates a process. A program can be a command, a shell script, or any binary executable or anyapplication. However, not all commands end up in creating process, there are some exceptions. Similar to how a filecreated has properties associated with it, a process also has lots of properties associated to it. In Unix, a background

 process executes independently of the shell, leaving the terminal free for other work. To run a process in the background, include an & (an ampersand) at the end of the command you use to run the job. Following are someexamples: 

To run the count program, which will display the process identification number of the job, enter:

count &

To check the status of your job, enter:

 ps

To bring a background process to the foreground, enter:

fg

If you have more than one job suspended in the background, enter:

fg %#

Replace # with the job number, as shown in the first column of the output of the jobs command

You can kill a background process by entering:

kill PID

Replace PID with the process ID of the job. If that fails, enter the following:

kill -KILL PID

To determine a job's PID, enter:

 jobs -l

If you are using sh, ksh, bash, or zsh, you may prevent background processes from sending error messages to theterminal. Redirect the output to /dev/null using the following syntax:

count 2> /dev/null &

Q 5) Demonstrate how and when you can use the followingcommands: vi, cat, chmod, grep, man, pwd, ps, kill, mkdir, rm.

Page 5: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 5/6

 Ans.VI:The UNIX vi editor is a full screen editor and has two modes of operation:1.Command mode commands which cause action to be taken on the file, and.2.Insert mode in which entered text is inserted into the file.CAT:The cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operatingsystems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect

output in terminal or files.CHMOD:In Unix-like operating systems, chmod is the command and system call which may change the access permissions tofile system objects (files and directories). It may also alter special mode flags. The request is filtered by the umask. Thename is an abbreviation of change modeGREP:grep prints lines of input matching a specified patterngrep [OPTIONS] PATTERN [FILE...]grep searches the named input FILEs (or standard input if no files are named, or if a single dash ("-") is given as the filename) for lines containing a match to the given PATTERN. By default, grep prints the matching linesMAN:In Unix, most programs, and many protocols, functions, and file formats, have accompanying manuals. With the man

command, you can retrieve the information in the manual and display it as text output on your screen. To use the mancommand, at the Unix prompt, enter:man topicReplace topic with the name of the manual item about which you want more information. For example, to find outmore about the FTP command, at the Unix prompt, enter:man ftpIf you are unsure which manual item you want to read, you can do a keyword search. At the Unix prompt, enter:man -k keyword | moreOn some systems, you need to replace man -k with apropos. For example, at the Unix prompt, enter:apropos keyword | moreIn both of the examples above, replace keyword with a specific topic (e.g., ftp, mail).For more information about the man command, at the Unix prompt, enter:man manPWD:

 pwd is one of the most basic commands in Linux and other Unix-like operating systems, along with ls, which is used tolist the contents of the current directory, and cd, which is used to change the current directory.PS:On every UNIX-like operating system, the process status command (ps) displays information about active processes.Every operating system's version of ps is slightly different, so consult your own documentation for specific options.This documentation describes a version of ps common to many distributions of Linux.KILL:Kill command in UNIX and Linux is normally used to kill a suspended or hanged process or process group. Thoughkill is mainly associated with kill operation its mere a signal transporter and can send specified signal to specified

 process in UNIX or UNIX like systems e.g. Linux, Solaris or FreeBSD. Like in windows when we see a particular process hung the system we go to task-manager find the process and kill it, similarly in UNIX and Linux we first find

the process ID (PID) of offending process and then kill it. Though we have killAll command also which doesn't requirePID instead it can kill the process with just process name. Kill commands is often a wrapper around kill () system call

 but some Linux systems also has built-in kill in place. In this article we will see some examples of kill command inUNIX and how we can use kill command to kill the locked processMKDIR:The mkdir command creates a single directories or multiple directories. Options. Sets the access mode for the newdirectory. If the parent directories don't exist, this command creates themRM:rm (short for remove) is a basic UNIX command used to remove objects such as files, directories, device nodes,symbolic links, and so on from the filesystem. To be more precise, rm removes references to objects from thefilesystem, where those objects might have had multiple references (for example, a file with two different names), andthe objects themselves are discarded only when all references have been removed and no programs still have open

handles to the objects.This allows for scenarios where a program can open a file, immediately remove it from thefilesystem, and then use it for temporary space, knowing that the file's space will be reclaimed after the program exits,even if it exits by crashing.

Q.6) Write a C program that illustrates the creation of child process using fork system call. One processfinds sum of even series and other process finds sum of odd series.

Page 6: FREE BCA SEM5 Unix 2014 .docx

7/27/2019 FREE BCA SEM5 Unix 2014 .docx

http://slidepdf.com/reader/full/free-bca-sem5-unix-2014-docx 6/6

Ans.#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <fcntl.h>int main(){int i,n,sum=0; pid_t pid;

system(“clear”);  printf(“Enter n value:”); scanf(“%d”,&n)  pid=fork();if(pid==0){ printf(“From child process\n”); for(i=1;i<n;i+=2){ printf(“%d\”,i); sum+=i;}

 printf(“Odd sum:%d\n”,sum); }else{ printf(“From process\n”); for(i=0;i<n;i+=2){ printf(“%d\”,i); sum+=i;} printf(“Even sum:%d\n”,sum); }}