Unix Viva Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

www.jntuworld.

com 36

Viva Questions & Answers


What is a Make file?
Make file is a utility in Unix to help compile large programs. It helps by only compiling the portion of the program that has been changed

Could you tell something about the Unix System Kernel?


The kernel is the heart of the UNIX operating system, its responsible for controlling the computers resources and scheduling user jobs so that each one gets its fair share of resources.

How can you tell what shell you are running on UNIX system?
You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -l and look for the shell with []

What do you mean by u-area (user area) or u-block?


This contains the private data that is manipulated only by the Kernel. This is local to the Process, i.e. each process is allocated a u-area.

What scheme does the Kernel in Unix System V follow while choosing a swap device among the multiple swap devices?
Kernel follows Round Robin scheme choosing a swap device among the multiple swap devices in Unix System V.

List the system calls used for process management:


System calls fork() exec() wait() [] Description To create a new process To execute a new program in a process

www.jntuworld.com

www.jntuworld.com 37

How do you change File Access Permissions?


Every file has following attributes: owners user ID ( 16 bit integer ) owners group ID ( 16 bit integer ) File access mode word r w x -r w x- r w x (user permission-group permission-others permission) r-read, w-write, x-execute To change the access mode, we use chmod(filename,mode). Example: To change mode of myfile to rw-rw-r (ie. read, write permission for user - []

Explain the layered aspect of a UNIX system. What are the layers? What does it mean to say they are layers?
A UNIX system has essentially three main layers: . The hardware . The operating system kernel . The user-level programs The kernel hides the systems hardware underneath an abstract, high-level programming interface. It is responsible for implementing many of the facilities that users and user-level programs take for granted. The kernel assembles all of the following UNIX concepts from lower-level []

What is the use of grep command?


grep is a pattern search command. It searches for the pattern, specified in the command line with appropriate option, in a file(s). Syntax : grep Example : grep 99mx mcafile

What difference between cmp and diff commands?


cmp - Compares two files byte by byte and displays the first mismatch diff - tells the changes to be made to make the files identical

What is the significance of the tee command?

www.jntuworld.com

www.jntuworld.com 38 It reads the standard input and sends it to the standard output while redirecting a copy of what it has read to the file specified by the user.

Is du a command? If so, what is its use?


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

How to terminate a process which is running and the specialty on command kill 0?
With the help of kill command we can terminate the process. Syntax: kill pid Kill 0 - kills all processes in your system except the login shell.

www.jntuworld.com

www.jntuworld.com 39

Explain kill() and its possible return values.


There are four possible results from this call: kill() returns 0. This implies that a process exists with the given PID, and the system would allow you to send signals to it. It is system-dependent whether the process could be a zombie. kill() returns -1, errno == ESRCH either no process exists with the given PID, or []

What does the command $who | sort logfile > newfile do?
The input from a pipe can be combined with the input from a file . The trick is to use the special symbol - (a hyphen) for those commands that recognize the hyphen as std input. In the above command the output from who becomes the std input to sort , meanwhile sort opens the file []

What are shell variables?


Shell variables are special variables, a name-value pair created and maintained by the shell. Example: PATH, HOME, MAIL and TERM

How many prompts are available in a UNIX system?


Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).

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


Use su command. The system asks for password and when valid entry is made the user gains super user (admin) privileges.

How the Kernel handles the copy on write bit of a page, when the bit is set?
In situations like, where the copy on write bit of a page is set and that page is shared by more than one process, the Kernel allocates new page and copies the content to the new page and the other processes retain their references to the old page. After copying the Kernel updates the page []

Difference between the fork() and vfork() system call?

www.jntuworld.com

www.jntuworld.com 40 During the fork() system call the Kernel makes a copy of the parent processs address space and attaches it to the child process.But the vfork() system call do not makes any copy of the parents address space, so it is faster than the fork() system call. The child process as a result of the vfork() []

How the Kernel handles the fork() system call in traditional Unix and in the System V Unix, while swapping?
Kernel in traditional Unix, makes the duplicate copy of the parents address space and attaches it to the childs process, while swapping. Kernel in System V Unix, manipulates the region tables, page table, and pfdata table entries, by incrementing the reference count of the region table of shared regions.

What are the requirements for a swapper to work?


The swapper works on the highest scheduling priority. Firstly it will look for any sleeping process, if not found then it will look for the ready-to-run process for swapping. But the major requirement for the swapper to work the ready-to-run process must be core-resident for at least 2 seconds before swapping out. And for swapping []

What is Expansion swap?


At the time when any process requires more memory than it is currently allocated, the Kernel performs Expansion swap. To do this Kernel reserves enough space in the swap device. Then the address translation mapping is adjusted for the new virtual address space but the physical memory is not allocated. At last Kernel swaps the []

What is Fork swap?


fork() is a system call to create a child process. When the parent process calls fork() system call, the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. []

What are the entities that are swapped out of the main memory while swapping the process out of the main memory?

www.jntuworld.com

www.jntuworld.com 41 All memory space occupied by the process, processs u-area, and Kernel stack are swapped out, theoretically. Practically, if the processs u-area contains the Address Translation Tables for the process then Kernel implementations do not swap the u-area.

Is the Process before and after the swap are the same? Give reason.
Process before swapping is residing in the primary memory in its original form. The regions (text, data and stack) may not be occupied fully by the process, there may be few empty slots in any of the regions and while swapping Kernel do not bother about the empty slots while swapping the process outAfter swapping []

What are the events done by the Kernel after a process is being swapped out from the main memory?
When Kernel swaps the process out of the primary memory, it performs the following: Kernel decrements the Reference Count of each region of the process. If the reference count becomes zero, swaps the region out of the main memory. Kernel allocates the space for the swapping process in the swap device. Kernel locks the other swapping process while []

What is major difference between the Historic Unix and the new BSD release of Unix System V in terms of Memory Management?
Historic Unix uses Swapping entire process is transferred to the main memory from the swap device, whereas the Unix System V uses Demand Paging only the part of the process is moved to the main memory. Historic Unix uses one Swap Device and Unix System V allow multiple Swap Devices

What is an advantage of executing a process in background?


The most common reason to put a process in the background is to allow you to do something else interactively without waiting for the process to complete. At the end of the command you add the special background symbol, &. This symbol tells your shell

www.jntuworld.com

www.jntuworld.com 42 to execute the given command in the background. Example: cp *.* []

What Happens when you execute a program?


When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system. Each process has process context, which is everything that is unique about the state of []

What are the process states in Unix?


As a process executes it changes state according to its circumstances. Unix processes have the following states: Running : The process is either running or it is ready to run . Waiting : The process is waiting for an event or for a resource. Stopped : The process has been stopped, usually by receiving a signal. Zombie : The []

www.jntuworld.com

www.jntuworld.com 43

What is a zombie?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the childs exit status. To be able to get this information, the parent calls `wait(); In the []

How can a parent and child process communicate?


A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the []

How can you get/set an environment variable from a program?


Getting the value of an environment variable is done by using `getenv(). Setting the value of an environment variable is done by using `putenv().

Explain fork() system call.


The `fork() used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork(). The parent gets the childs pid returned to him, but []

What are various IDs associated with a process?


Unix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the parent process whose PID is Parent Process ID. Every process is associated with a particular user called the owner who has privileges over the process. The identification for the user is []

Brief about the initial process sequence while the system boots up.

www.jntuworld.com

www.jntuworld.com 44 While booting, special process called the swapper or scheduler is created with Process-ID 0. The swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn creates 3 children: the process dispatcher,vhand and dbflush with IDs 1,2 and 3 respectively. This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. []

www.jntuworld.com

www.jntuworld.com 45

What is a shell?
A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. The shell converts them to system calls to the OS or forks off a process to execute the command. System call results and other information from the OS []

How does the inode map to data block of a file?


Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks in the file. The 11th address points to a one-level index block. The 12th address points to a two-level (double in-direction) index block. The 13th address points to a three-level(triple in-direction)index block. This provides a very large maximum []

Discuss the mount and unmount system calls


The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to []

How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence. 1. kernel assigns new inode, 2. sets the file type to indicate that the file is a pipe, directory or special file, 3. If it is a device file, it makes the other entries like major, minor device numbers. For example: If the device is a disk, major []

What are links and symbolic links in UNIX file system?


A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers.

www.jntuworld.com

www.jntuworld.com 46 Symbolic link is a file that only contains the name of another file.Operation []

What are the Unix system calls for I/O?


open(pathname,flag,mode) - open file creat(pathname,mode) - create file close(filedes) - close an open file read(filedes,buffer,bytes) - read data from an open file write(filedes,buffer,bytes) - write data to an open file lseek(filedes,offset,from) - position an open file dup(filedes) - duplicate an existing file descriptor dup2(oldfd,newfd) - duplicate to a desired file descriptor fcntl(filedes,cmd,arg) - change properties of an open file ioctl(filedes,request,arg) - change the behaviour []

What Happens when you execute a program?


When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system. Each process has process context, which is everything that is unique about the state of []

What are the process states in Unix?


As a process executes it changes state according to its circumstances. Unix processes have the following states: Running : The process is either running or it is ready to run . Waiting : The process is waiting for an event or for a resource. Stopped : The process has been stopped, usually by receiving a signal. Zombie : The []

What is a zombie?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the childs exit status. To be able to get this information, the parent calls `wait(); In the []

How can a parent and child process communicate?

www.jntuworld.com

www.jntuworld.com 47 A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the []

How can you get/set an environment variable from a program?


Getting the value of an environment variable is done by using `getenv(). Setting the value of an environment variable is done by using `putenv().

Explain fork() system call.


The `fork() used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork(). The parent gets the childs pid returned to him, but []

What are various IDs associated with a process?


Unix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the parent process whose PID is Parent Process ID. Every process is associated with a particular user called the owner who has privileges over the process. The identification for the user is []

Brief about the initial process sequence while the system boots up.
While booting, special process called the swapper or scheduler is created with Process-ID 0. The swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn creates 3 children: the process dispatcher,vhand and dbflush with IDs 1,2 and 3 respectively. This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. []

What is a shell?

www.jntuworld.com

www.jntuworld.com 48 A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. The shell converts them to system calls to the OS or forks off a process to execute the command. System call results and other information from the OS []

How does the inode map to data block of a file?


Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks in the file. The 11th address points to a one-level index block. The 12th address points to a two-level (double in-direction) index block. The 13th address points to a three-level(triple in-direction)index block. This provides a very large maximum []

Discuss the mount and unmount system calls


The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to []

How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence. 1. kernel assigns new inode, 2. sets the file type to indicate that the file is a pipe, directory or special file, 3. If it is a device file, it makes the other entries like major, minor device numbers. For example: If the device is a disk, major []

What is a FIFO?
FIFO are otherwise called as named pipes. FIFO (first-in-firstout) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of []

www.jntuworld.com

www.jntuworld.com 49

What are links and symbolic links in UNIX file system?


A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers. Symbolic link is a file that only contains the name of another file.Operation []

What are the Unix system calls for I/O?


open(pathname,flag,mode) - open file creat(pathname,mode) - create file close(filedes) - close an open file read(filedes,buffer,bytes) - read data from an open file write(filedes,buffer,bytes) - write data to an open file lseek(filedes,offset,from) - position an open file dup(filedes) - duplicate an existing file descriptor dup2(oldfd,newfd) - duplicate to a desired file descriptor fcntl(filedes,cmd,arg) - change properties of an open file ioctl(filedes,request,arg) - change the behaviour []

Brief about the directory representation in UNIX


s a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries []

What is inode?
All UNIX files have its description stored in a structure called inode. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers []

www.jntuworld.com

www.jntuworld.com 50

How are devices represented in UNIX?


All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A regular file is just an ordinary data file in the disk. A block special file represents a device with characteristics similar to a disk (data transfer []

Brief about the directory representation in UNIX


A Unix directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries []

What is inode?
All UNIX files have its description stored in a structure called inode. The inode contains info about the file-size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. In addition to descriptions about the file, the inode contains pointers []

How are devices represented in UNIX?


All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A regular file is just an ordinary data file in the disk. A block special file represents a device with characteristics similar to a disk (data transfer []
How is the command $cat file2 different from $cat >file2 Answer The Commond $cat file in unix is used to display the content of the file and where as commond $cat >> file is to append the text to the end of the file without overwritting the information of the file. Incase if the file does not exist in the directory the commond will create a newfile in file system.

www.jntuworld.com

www.jntuworld.com 51

$cat >file means to create a new file $cat file means to open an existing file.
Answered By: selva,ravi Date: 7/13/2007

cat > file it means creating file for file cat file it means used to display the file content

Explain the steps that a shell follows while processing a command. When processing a command the searchs for the utility for the command in the directories specified in the PATH varible and it in invokes that utility. That utility will execute the command with help of kernel and the output is given to shell. And then the displays out put to the user.

Answer

Explain the steps that a shell follows while processing a command. When processing a command the searchs for the utility for the command in the directories specified in the PATH varible and it in invokes that utility. That utility will execute the command with help of kernel and the output is given to shell. And then the displays out put to the user.

Answer

Which command is used to delete all files in the current directory and all its subdirectories?

#rm -fr <Directory name> # rm -rf * Answer


Answered By: Amit Shiknis Date: 12/25/2007

rm -r *

www.jntuworld.com

www.jntuworld.com 52

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

Answer

Yes you are correct. It stands for listing the files Chapter with suffix 1 to 5 but it will display the files in columns as with-x option.

How does the kernel differentiate device files and ordinary files?

Device filles are of 2 types --- charcater device file and block device file type field in the file's inode structure Answer b--- block device file c--- character device file

How to switch to a super user status to gain privileges?

Answer

Use su command. The system asks for password and when valid entry is made the user gains super user (admin) privileges.

What are shell variables?

Answer

Shell variables are system environment variables.They include TERM,SHELL, MAIL the output of the shell variable we can see by typing the command

www.jntuworld.com

www.jntuworld.com 53

$>echo $TERM ansi at the prompt.

What is redirection?

Redirection is a feature in Unix where the data from the standard out put or a file,so on.can be redirected i.e divert to a file or a program and vice versa. Answer > -- out put redirection >> -- out put redirectin(appending at the last) < -- input redirection

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

Answer

With the help of kill command we can terminate the process. Syntax: kill pid Kill 0 - kills all processes in your system except the login shell.

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

Answer

With the help of kill command we can terminate the process. Syntax: kill pid Kill 0 - kills all processes in your system except the login shell.

How to sfind free space in unix/linux

www.jntuworld.com

www.jntuworld.com 54

Answer

Df and du commands are used for checking free space on disk . df -h or df -Humanreadable gives human readable format of free space.

What is the difference between soft link and hard link in unix operating system ?

Hard Links : 1. All Links have same inode number. 2.ls -l command shows all the links with the link column(Second) shows No. of links. 3. Links have actual file contents 4.Removing any link ,just reduces the link count , but doesn't affect other links. Answer Soft Links(Symbolic Links) : 1.Links have different inode numbers. 2. ls -l command shows all links with second column value 1 and the link points to original file. 3. Link has the path for original file and not the contents. 4.Removing soft link doesn't affect anything but removing original file ,the link becomes "dangling" link which points to nonexistant file.

to concatenate (attach) two strings?

For concatenating two string we use cat command. Answer Ex:- cat str1 str2

Explain the UNIX Kernel.

www.jntuworld.com

www.jntuworld.com 55

Answer

UNIX Kernel is heart of the operating system. UNIX kernal is loaded first when UNIX system is booted. It handles allocation of devices, cpu, memory from that ponint on.

How many prompts are available in a UNIX system?

Unix/ Linux Supports four Prompts PS1, PS2, PS3, PS4 Answer #,@,$,% are 4 prompts

REFERENCES: Books:
1)Introduction to UNIX & SHELL programming, M.G. Venkatesh Murthy, Pearson Education. 2)Unix concepts and applications, Fourth Edition, Sumitabha Das, TMH.

www.jntuworld.com

You might also like