{"id":243,"date":"2010-04-16T08:49:31","date_gmt":"2010-04-16T08:49:31","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/04\/16\/interview-questions-sets-shell-script-descriptive\/"},"modified":"2022-12-22T14:37:03","modified_gmt":"2022-12-22T14:37:03","slug":"interview-questions-sets-shell-script-descriptive","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/interview-questions-sets-shell-script-descriptive\/","title":{"rendered":"Shell Bash Scripting Interview Questions and Answer \u2013 Part 1"},"content":{"rendered":"<h3><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4304 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1.png\" alt=\"shell-script-descriptive-interview-questions-sets\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/interview-questions-sets-sh-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/h3>\n<h3 style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">Interview Questions Sets : Shell Script Descriptive Questions Sets<br \/>\n<\/span><\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>What is shell scripting?<\/strong><br \/>\nShell scripting is used to program <span style=\"text-decoration: underline;\">command line of an operating system<\/span>. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to program operating systems of windows, UNIX, Apple, etc. Also this script is used by companies to develop their own operating system with their own features.<\/span><\/span><\/p>\n<p><strong>Advantages of Shell scripting?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThere are many advantages of shell scripting some of them are, one can develop their own operating system with relevant features best suited to their organization than to rely on costly operating systems. Software applications can be designed according to their platform.<\/span><\/p>\n<p><strong>What are the disadvantages of shell scripting?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThere are many disadvantages of shell scripting they are<br \/>\n<\/span><\/p>\n<ul>\n<li><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">Design flaws can destroy the entire process and could prove a costly error.<\/span><\/span><\/li>\n<li><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"> Typing errors during the creation can delete the entire data as well as partition data.<\/span><\/span><\/li>\n<li><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"> Initially process is slow but can be improved.<\/span><\/span><\/li>\n<li><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"> *Portbility between different operating system is a prime concern as it is very difficult to port scripts etc.<\/span><\/span><\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><br \/>\n<\/span><span style=\"font-family: verdana,geneva;\"><strong>Explain about the slow execution speed of shells?<\/strong><br \/>\nMajor disadvantage of using shell scripting is slow execution of the scripts. This is because for every command a new process needs to be started. This slow down can be resolved by using pipeline and filter commands. A complex script takes much longer time than a normal script.<\/span><\/span><\/p>\n<p><strong>Give some situations where typing error can destroy a program?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThere are many situations where typing errors can prove to be a real costly effort. For example a single extra space can convert the functionality of the program from deleting the sub directories to files deletion. cp, cn, cd all resemble the same but their actual functioning is different. Misdirected &gt; can delete your data.<br \/>\nCoding Related Shell Scripting Interview Questions &#8230;<\/span><\/p>\n<p><strong>Explain about return code?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nReturn code is a common feature in shell programming. These return codes indicate whether a particular program or application has succeeded or failed during its process. &amp;&amp; can be used in return code to indicate which application needs to be executed first.<\/span><\/p>\n<p><strong>What are the different variables present in Linux shell?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nVariables can be defined by the programmer or developer they specify the location of a particular variable in the memory. There are two types of shells they are System variables and user defined variables. System variables are defined by the system and user defined variables are to be defined by the user (small letters).<\/span><\/p>\n<p><strong>Explain about GUI scripting?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nGraphical user interface provided the much needed thrust for controlling a computer and its applications. This form of language simplified repetitive actions. Support for different applications mostly depends upon the operating system. These interact with menus, buttons, etc.<br \/>\n<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><span style=\"text-decoration: underline;\"><strong>Shell Scripting Command Interview Questions &#8230;<\/strong><\/span><\/span><\/span><\/p>\n<p><strong>Explain about echo command?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nEcho command is used to display the value of a variable. There are many different options give different outputs such as usage \\c suppress a trailing line, \\r returns a carriage line, -e enables interpretation, \\r returns the carriage.<\/span><\/p>\n<p><strong>Explain about Stdin, Stdout and Stderr?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThese are known as standard input, output and error. These are categorized as 0, 1 and 2. Each of these functions has a particular role and should accordingly functions for efficient output. Any mismatch among these three could result in a major failure of the shell.<\/span><\/p>\n<p><strong>Explain about sourcing commands?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nSourcing commands help you to execute the scripts within the scripts. For example sh command makes your program to run as a separate shell. .command makes your program to run within the shell. This is an important command for beginners and for special purposes.<\/span><\/p>\n<p><strong>Explain about debugging?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nShell can make your debugging process easier because it has lots of commands to perform the function. For example sh \u2013ncommand helps you to perform debugging. It helps you to read the shell but not to execute it during the course. Similarly sh \u2013x command helps you by displaying the arguments and functions as they are executed.<\/span><\/p>\n<p><strong>Explain about Login shell?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nLogin shell is very useful as it creates an environment which is very useful to create the default parameters. It consists of two files they are profile files and shell rc files. These files initialize the login and non login files. Environment variables are created by Login shell.<\/span><\/p>\n<p><strong>Explain about non-login shell files?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe non login shell files are initialized at the start and they are made to run to set up variables. Parameters and path can be set etc are some important functions. These files can be changed and also your own environment can be set. These functions are present in the root. It runs the profile each time you start the process.<\/span><\/p>\n<p><strong>Explain about shebang?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nShebang is nothing but a # sign followed by an exclamation. This is visible at the top of the script and it is immediately followed by an exclamation. To avoid repetitive work each time developers use shebang. After assigning the shebang work we pass info to the interpreter.<\/span><\/p>\n<p><strong>Explain about the Exit command?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nEvery program whether on UNIX or Linux should end at a certain point of time and successful completion of a program is denoted by the output 0. If the program gives an output other than 0 it defines that there has been some problem with the execution or termination of the problem. Whenever you are calling other function, exit command gets displayed.<\/span><\/p>\n<p><strong>Explore about Environment variables?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nEnvironment variables are set at the login time and every shell that starts from this shell gets a copy of the variable. When we export the variable it changes from an shell variable to an environment variable and these variables are initiated at the start of the shell.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>How can you tell what shell you are running on a UNIX system?<\/strong><br \/>\nAnswer :<br \/>\nYou can do the Echo $RANDOM. It will return a undefined variable if you are from the <strong>C-Shell,<\/strong> just a return prompt if you are from the <strong>Bourne shell<\/strong>, and a 5 digit random numbers if you are from the Korn shell. <\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">You could also do a ps -l and look for the shell with the highest PID.<br \/>\n<\/span><span style=\"font-family: verdana,geneva;\"><br \/>\n<strong>What are conditions on which deadlock can occur while swapping the processes?<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\nAll processes in the main memory are asleep. All \u2018ready-to-run\u2019 processes are swapped out.<br \/>\nThere is no space in the swap device for the new incoming process that are swapped out of the main memory. There is no space in the main memory for the new incoming process.<br \/>\n<\/span><span style=\"font-family: verdana,geneva;\"><br \/>\n<strong>How do you change File Access Permissions?<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\n<strong>Answer :<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\nEvery file has following attributes:<br \/>\nowner\u2019s user ID ( 16 bit integer )<br \/>\nowner\u2019s group ID ( 16 bit integer )<br \/>\nFile access mode word<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">\u2018r w x -r w x- r w x\u2019<br \/>\n(user permission-group permission-others permission)<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">r-read, w-write, x-execute<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">To change the access mode, we use chmod(filename,mode).<br \/>\n<strong>Example:<\/strong><br \/>\nTo change mode of myfile to \u2018rw-rw-r\u2013\u2019 (ie. read, write permission for user &#8211; read,write permission for group &#8211; only read permission for others) we give the args as:<br \/>\nchmod(myfile,0664) .<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">Each operation is represented by discrete values<br \/>\n\u2018r\u2019 is 4<br \/>\n\u2018w\u2019 is 2<br \/>\n\u2018x\u2019 is 1<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">Therefore, for \u2018rw\u2019 the value is 6(4+2).<br \/>\n<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>Example 2:<\/strong><br \/>\nTo change mode of myfile to \u2018rwxr\u2013r\u2013\u2019 we give the args as:<br \/>\nchmod(myfile,0744). <\/span><\/span><\/p>\n<p><strong>List the system calls used for process management.<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\n<strong>Answer :<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\nSystem calls Description<br \/>\nfork() To create a new process<br \/>\nexec() To execute a new program in a process<br \/>\nwait() To wait until a created process completes its execution<br \/>\nexit() To exit from a process execution<br \/>\ngetpid() To get a process identifier of the current process<br \/>\ngetppid() To get parent process identifier<br \/>\nnice() To bias the existing priority of a process<br \/>\nbrk() To increase\/decrease the data segment size of a process <\/span><\/p>\n<p><strong>What is the difference between Swapping and Paging?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nAnswer:<\/span><\/p>\n<p>Swapping:<span style=\"font-family: verdana,geneva;\"><br \/>\nWhole process is moved from the swap device to the main memory for execution. Process size must be less than or equal to the available main memory. It is easier to implementation and overhead to the system. Swapping systems does not handle the memory more flexibly as compared to the paging systems.<\/span><\/p>\n<p>Paging:<span style=\"font-family: verdana,geneva;\"><br \/>\nOnly the required memory pages are moved to main memory from the swap device for execution. Process size does not matter. Gives the concept of the virtual memory.<\/span><\/p>\n<p>It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.<\/p>\n<p><strong>What is the difference between cmp and diff commands?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nAnswer :<\/span><\/p>\n<p>cmp &#8211; Compares two files byte by byte and displays the first mismatch<span style=\"font-family: verdana,geneva;\"><br \/>\ndiff &#8211; tells the changes to be made to make the files identical<\/span><\/p>\n<p><strong>What is meant by the nice value?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nAnswer :<\/span><\/p>\n<p>Nice value is the value that controls {increments or decrements} the priority of the process. This value that is returned by the nice () system call. The equation for using nice value is:<span style=\"font-family: verdana,geneva;\"><br \/>\nPriority = (\u201crecent CPU usage\u201d\/constant) + (base- priority) + (nice value)<br \/>\nOnly the administrator can supply the nice value. The nice () system call works for the running process only. Nice value of one process cannot affect the nice value of the other process. <\/span><\/p>\n<p><strong>What is a daemon?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nAnswer :<br \/>\nA daemon is a process that detaches itself from the terminal and runs, disconnected, in the background, waiting for requests and responding to them. It can also be defined as the background process that does not belong to a terminal session. Many system functions are commonly performed by daemons, including the sendmail daemon, which handles mail, and the NNTP daemon, which handles USENET news. Many other daemons may exist. Some of the most common daemons are:<br \/>\ninit: Takes over the basic running of the system when the kernel has finished the boot process.<br \/>\ninetd: Responsible for starting network services that do not have their own stand-alone daemons. For example, inetd usually takes care of incoming rlogin, telnet, and ftp connections.<br \/>\ncron: Responsible for running repetitive tasks on a regular schedule.<br \/>\n<strong><br \/>\nWhat are the process states in UNIX?<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\nAnswer :<br \/>\nAs a process executes it changes state according to its circumstances. Unix processes have the following states:<br \/>\nRunning : The process is either running or it is ready to run .<br \/>\nWaiting : The process is waiting for an event or for a resource.<br \/>\nStopped : The process has been stopped, usually by receiving a signal.<br \/>\nZombie : The process is dead but have not been removed from the process table.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>How are devices represented in UNIX?<\/strong><br \/>\nAll 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 &#8216;regular file&#8217; is just an ordinary data file in the disk. A &#8216;block special file&#8217; represents a device with characteristics similar to a disk (data transfer in terms of blocks). A &#8216;character special file&#8217; represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).<\/span><\/span><\/p>\n<p><strong>What is &#8216;inode&#8217;?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nAll UNIX files have its description stored in a structure called &#8216;inode&#8217;. 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 to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this further aggregates for larger files). A block is typically 8k.<br \/>\nInode consists of the following fields:<br \/>\n\u2022 File owner identifier<br \/>\n\u2022 File type<br \/>\n\u2022 File access permissions<br \/>\n\u2022 File access times<br \/>\n\u2022 Number of links<br \/>\n\u2022 File size<br \/>\n\u2022 Location of the file data<\/span><\/p>\n<p><strong>Brief about the directory representation in UNIX<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nA 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 named &#8216;.&#8217; (refers to the directory itself) and &#8216;..&#8217; (refers to parent directory).<br \/>\nSystem call for creating directory is mkdir (pathname, mode).<\/span><\/p>\n<p><strong>What are the Unix system calls for I\/O?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\n\u2022 open(pathname,flag,mode) &#8211; open file<br \/>\n\u2022 creat(pathname,mode) &#8211; create file<br \/>\n\u2022 close(filedes) &#8211; close an open file<br \/>\n\u2022 read(filedes,buffer,bytes) &#8211; read data from an open file<br \/>\n\u2022 write(filedes,buffer,bytes) &#8211; write data to an open file<br \/>\n\u2022 lseek(filedes,offset,from) &#8211; position an open file<br \/>\n\u2022 dup(filedes) &#8211; duplicate an existing file descriptor<br \/>\n\u2022 dup2(oldfd,newfd) &#8211; duplicate to a desired file descriptor<br \/>\n\u2022 fcntl(filedes,cmd,arg) &#8211; change properties of an open file<br \/>\n\u2022 ioctl(filedes,request,arg) &#8211; change the behaviour of an open file<br \/>\nThe difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device-specific operations.<\/span><\/p>\n<p><strong>How do you change File Access Permissions?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nEvery file has following attributes:<br \/>\n\u2022 owner&#8217;s user ID ( 16 bit integer )<br \/>\n\u2022 owner&#8217;s group ID ( 16 bit integer )<br \/>\n\u2022 File access mode word<br \/>\n&#8216;r w x -r w x- r w x&#8217;<br \/>\n(user permission-group permission-others permission)<br \/>\nr-read, w-write, x-execute<br \/>\nTo change the access mode, we use chmod(filename,mode).<br \/>\nExample 1:<br \/>\nTo change mode of myfile to &#8216;rw-rw-r&#8211;&#8216; (ie. read, write permission for user &#8211; read,write permission for group &#8211; only read permission for others) we give the args as:<br \/>\nchmod(myfile,0664) .<br \/>\nEach operation is represented by discrete values<br \/>\n&#8216;r&#8217; is 4<br \/>\n&#8216;w&#8217; is 2<br \/>\n&#8216;x&#8217; is 1<br \/>\nTherefore, for &#8216;rw&#8217; the value is 6(4+2).<br \/>\nExample 2:<br \/>\nTo change mode of myfile to &#8216;rwxr&#8211;r&#8211;&#8216; we give the args as:<br \/>\nchmod(myfile,0744).<\/span><\/p>\n<p>What are links and symbolic links in UNIX file system?<span style=\"font-family: verdana,geneva;\"><br \/>\nA 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.<br \/>\nSymbolic link &#8216;is&#8217; a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links.<br \/>\nCommands for linking files are:<br \/>\nLink ln filename1 filename2<br \/>\nSymbolic link ln -s filename1 filename2<\/span><\/p>\n<p><strong>What is a FIFO?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nFIFO are otherwise called as &#8216;named pipes&#8217;. FIFO (first-in-first-out) 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 the pipe (producer) and the other reads from the other end (consumer).<\/span><\/p>\n<p><strong>How do you create special files like named pipes and device files?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe system call mknod creates special files in the following sequence.<br \/>\nkernel assigns new inode,<br \/>\nsets the file type to indicate that the file is a pipe, directory or special file,<br \/>\nIf it is a device file, it makes the other entries like major, minor device numbers.<br \/>\nFor example:<br \/>\nIf the device is a disk, major device number refers to the disk controller and minor device number is the disk.<\/span><\/p>\n<p><strong>Discuss the mount and unmount system calls<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe 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 mount call is the mount point, that is , a directory in the current file naming system. The second argument is the file system to mount to that point. When you insert a cdrom to your unix system&#8217;s drive, the file system in the cdrom automatically mounts to \/dev\/cdrom in your system.<\/span><\/p>\n<p><strong>How does the inode map to data block of a file?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nInode 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 file size with efficient access to large files, but also small files are accessed directly in one disk read.<\/span><\/p>\n<p><strong>What is a shell?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nA 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 are presented to the user through an interactive interface. Commonly used shells are sh,csh,ks etc.<\/span><\/p>\n<p><strong>Brief about the initial process sequence while the system boots up.<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nWhile booting, special process called the &#8216;swapper&#8217; or &#8216;scheduler&#8217; is created with Process-ID 0. The swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn creates 3 children:<br \/>\n\u2022 the process dispatcher,<br \/>\n\u2022 vhand and<br \/>\n\u2022 dbflush<br \/>\nwith IDs 1,2 and 3 respectively.<br \/>\nThis is done by executing the file \/etc\/init. Process dispatcher gives birth to the shell. Unix keeps track of all the processes in an internal data structure called the Process Table (listing command is ps -el).<\/span><\/p>\n<p><strong>What are various IDs associated with a process?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nUnix identifies each process with a unique integer called ProcessID. The process that executes the request for creation of a process is called the &#8216;parent process&#8217; whose PID is &#8216;Parent Process ID&#8217;. Every process is associated with a particular user called the &#8216;owner&#8217; who has privileges over the process. The identification for the user is &#8216;UserID&#8217;. Owner is the user who executes the process. Process also has &#8216;Effective User ID&#8217; which determines the access privileges for accessing resources like files.<br \/>\ngetpid() -process id<br \/>\ngetppid() -parent process id<br \/>\ngetuid() -user id<br \/>\ngeteuid() -effective user id<\/span><\/p>\n<p><strong>Explain fork() system call.<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe `fork()&#8217; 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()&#8217;. The parent gets the child&#8217;s pid returned to him, but the child gets 0 returned to him.<\/span><\/p>\n<p><strong>Predict the output of the following program code<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nmain()<br \/>\n{<br \/>\nfork();<br \/>\nprintf(&#8220;Hello World!&#8221;);<br \/>\n}<br \/>\nAnswer:<br \/>\nHello World!Hello World!<br \/>\nExplanation:<br \/>\nThe fork creates a child that is a duplicate of the parent process. The child begins from the fork().All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.<\/span><\/p>\n<p><strong>Predict the output of the following program code<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nmain()<br \/>\n{<br \/>\nfork(); fork(); fork();<br \/>\nprintf(&#8220;Hello World!&#8221;);<br \/>\n}<br \/>\nAnswer:<br \/>\n&#8220;Hello World&#8221; will be printed 8 times.<br \/>\nExplanation:<br \/>\n2^n times where n is the number of calls to fork()<\/span><\/p>\n<p><strong>List the system calls used for process management:<br \/>\n<\/strong>System calls Description<span style=\"font-family: verdana,geneva;\"><br \/>\nfork() To create a new process<br \/>\nexec() To execute a new program in a process<br \/>\nwait() To wait until a created process completes its execution<br \/>\nexit() To exit from a process execution<br \/>\ngetpid() To get a process identifier of the current process<br \/>\ngetppid() To get parent process identifier<br \/>\nnice() To bias the existing priority of a process<br \/>\nbrk() To increase\/decrease the data segment size of a process<\/span><\/p>\n<p><strong>How can you get\/set an environment variable from a program?<br \/>\n<\/strong>Getting the value of an environment variable is done by using `getenv()&#8217;.<span style=\"font-family: verdana,geneva;\"><br \/>\nSetting the value of an environment variable is done by using `putenv()&#8217;.<\/span><\/p>\n<p><strong>How can a parent and child process communicate?<br \/>\n<\/strong>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 child.<\/p>\n<p><strong>What is a zombie?<br \/>\n<\/strong>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 &#8211; for example, the parent may need to check the child&#8217;s exit status. To be able to get this information, the parent calls `wait()&#8217;; In the interval between the child terminating and the parent calling `wait()&#8217;, the child is said to be a `zombie&#8217; (If you do `ps&#8217;, the child will have a `Z&#8217; in its status field to indicate this.)<\/p>\n<p><strong>What are the process states in Unix?<br \/>\n<\/strong>As a process executes it changes state according to its circumstances. Unix processes have the following states:<span style=\"font-family: verdana,geneva;\"><br \/>\nRunning : The process is either running or it is ready to run .<br \/>\nWaiting : The process is waiting for an event or for a resource.<br \/>\nStopped : The process has been stopped, usually by receiving a signal.<br \/>\nZombie : The process is dead but have not been removed from the process table.<\/span><\/p>\n<p><strong>What Happens when you execute a program?<br \/>\n<\/strong>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 the program you are currently running. Every time you execute a program the UNIX system does a fork, which performs a series of operations to create a process context and then execute your program in that context. The steps include the following:<span style=\"font-family: verdana,geneva;\"><br \/>\n\u2022 Allocate a slot in the process table, a list of currently running programs kept by UNIX.<br \/>\n\u2022 Assign a unique process identifier (PID) to the process.<br \/>\n\u2022 iCopy the context of the parent, the process that requested the spawning of the new process.<br \/>\n\u2022 Return the new PID to the parent process. This enables the parent process to examine or control the process directly.<br \/>\nAfter the fork is complete, UNIX runs your program.<\/span><\/p>\n<p><strong>What Happens when you execute a command?<br \/>\n<\/strong>When you enter &#8216;ls&#8217; command to look at the contents of your current working directory, UNIX does a series of things to create an environment for ls and the run it:<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">The shell has UNIX perform a fork. This creates a new process that the shell will use to run the ls program.<br \/>\nThe shell has UNIX perform an exec of the ls program. This replaces the shell program and data with the program and data for ls and then starts running that new program. <\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">The ls program is loaded into the new process context, replacing the text and data of the shell. The ls program performs its task, listing the contents of the current directory.<\/span><\/span><\/p>\n<p><strong>What is a Daemon?<br \/>\n<\/strong>A daemon is a process that detaches itself from the terminal and runs, disconnected, in the background, waiting for requests and responding to them. It can also be defined as the background process that does not belong to a terminal session. Many system functions are commonly performed by daemons, including the sendmail daemon, which handles mail, and the NNTP daemon, which handles USENET news. Many other daemons may exist. Some of the most common daemons are:<span style=\"font-family: verdana,geneva;\"><br \/>\n\u2022 init: Takes over the basic running of the system when the kernel has finished the boot process.<br \/>\n\u2022 inetd: Responsible for starting network services that do not have their own stand-alone daemons. For example, inetd usually takes care of incoming rlogin, telnet, and ftp connections.<br \/>\n\u2022 cron: Responsible for running repetitive tasks on a regular schedule.<\/span><\/p>\n<p><strong>What is &#8216;ps&#8217; command for?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe ps command prints the process status for some or all of the running processes. The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.<\/span><\/p>\n<p><strong>How would you kill a process?<br \/>\n<\/strong>The kill command takes the PID as one argument; this identifies which process to terminate. The PID of a process can be got using &#8216;ps&#8217; command.<\/p>\n<p><strong>What is an advantage of executing a process in background?<br \/>\n<\/strong>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, &amp;. This symbol tells your shell to execute the given command in the background.<span style=\"font-family: verdana,geneva;\"><br \/>\nExample: cp *.* ..\/backup&amp; (cp is for copy)<\/span><\/p>\n<p><strong>How do you execute one program from within another?<br \/>\n<\/strong>The system calls used for low-level process creation are execlp() and execvp(). The execlp call overlays the existing program with the new one , runs that and exits. The original program gets back control only when an error occurs.<span style=\"font-family: verdana,geneva;\"><br \/>\nexeclp(path,file_name,arguments..); \/\/last argument must be NULL<br \/>\nA variant of execlp called execvp is used when the number of arguments is not known in advance.<br \/>\nexecvp(path,argument_array); \/\/argument array should be terminated by NULL<\/span><\/p>\n<p><strong>What is IPC? What are the various schemes available?<br \/>\n<\/strong>The term IPC (Inter-Process Communication) describes various ways by which different process running on some operating system communicate between each other. Various schemes available are as follows:<span style=\"font-family: verdana,geneva;\"><br \/>\nPipes:<br \/>\nOne-way communication scheme through which different process can communicate. The problem is that the two processes should have a common ancestor (parent-child relationship). However this problem was fixed with the introduction of named-pipes (FIFO).<\/span><\/p>\n<p>Message Queues :<span style=\"font-family: verdana,geneva;\"><br \/>\nMessage queues can be used between related and unrelated processes running on a machine.<\/span><\/p>\n<p>Shared Memory:<span style=\"font-family: verdana,geneva;\"><br \/>\nThis is the fastest of all IPC schemes. The memory to be shared is mapped into the address space of the processes (that are sharing). The speed achieved is attributed to the fact that there is no kernel involvement. But this scheme needs synchronization.<\/span><\/p>\n<p><strong>State and explain about features of UNIX?<br \/>\n<\/strong>UNIX operating system originally was developed in 1969. This is an open source operating system developed by AT&amp;T. It is widely used in work stations and servers. It is designed to be multi tasking, multi user and portable. UNIX has many several components packed together.<\/p>\n<p><strong>Explain about sh?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nSh is the command line interpreter and it is the primary user interface. This forms the programmable command line interpreter. After windows appeared it still retained the programmable characteristics.<\/span><\/p>\n<p><strong>Explain about system and user utilities?<br \/>\n<\/strong>There are two utilities they are system and user utilities. System utilities contain administrative tools such as mkfs, fsck, etc. Where as user utilities contain features such as passwd, kill, etc. It basically contains environment values.<\/p>\n<p><strong>Explain about document formatting?<br \/>\n<\/strong>UNIX systems were primarily used for typesetting systems and document formatting. Modern UNIX systems used packages such as Tex and Ghostscript. It uses some of the programs such as nroff, tbl, troff, refer, eqn and pic. Document formatting is very used because it forms the base of UNIX.<\/p>\n<p><strong>Explain about communication features in UNIX?<br \/>\n<\/strong>Early UNIX systems used inter user communication programs mail and write commands. They never contained a fully embedded inter user communication features. Systems with BSD included TCP\/IP protocols.<\/p>\n<p><strong>Explain about chmod options filename?<br \/>\n<\/strong>This command allows you to change, write, read and execute permissions on your file. Changes can be done to the file system but at times you need to change permissions for the file systems. At times files should be executable for viewing the files.<\/p>\n<p><strong>Explain about gzip filename?<br \/>\n<\/strong>Gzip filename is used to compress the files so that those files take up less space. The size of the file actually gets reduced to half their size but they might also depend upon about the file size and nature of the file systems. Files using gzip file name end with .gz.<\/p>\n<p><strong>Explain about refer?<br \/>\n<\/strong>Refer was written in Bell Laboratories and it is implemented as a troff preprocessor. This program is used managing bibliographic references and it is used to cite them in troff documents. It is offered in most of the UNIX packages. It refers with text and reference file.<\/p>\n<p><strong>Explain about lpr filename?<br \/>\n<\/strong>This command is used to print a file. If you want to change the default print you can change the printer by using the P option. For double sided print you can use lpr-Pvalkyr-d. This is very useful command in UNIX present in many packages.<\/p>\n<p><strong>Explain about lprm job number?<br \/>\n<\/strong>This command is used to remove documents from the printer queue. The job number or the queue number can be found by using lpq. Printer name should be specified but this is not necessary if you want to use your default printer.<\/p>\n<p><strong>Brief about the command ff?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThis command finds files present anywhere on the system. This command is used to find document location where you forgot the directory in which you kept the file but you do remember about the name. This command is not restricted in finding files it displays files and documents relevant to the name.<\/span><\/p>\n<p><strong>Brief about finger username?<br \/>\n<\/strong>This command is used to give information about the user; it gives out a profile about the user. This command is very useful for administrators as it gives the log information, email, current log information, etc. finger also displays information such as phone number and name when they use a file called .plan.<\/p>\n<p><strong>Explain about the command elm?<br \/>\n<\/strong>This command lets you to send email message from your system. This command is not the only one which sends email there are lots of other messenger systems which can facilitate the process of sending a mail. This command behaves differently on different machines.<\/p>\n<p><strong>Brief about the command kill PID?<br \/>\n<\/strong>This command ends the process to which it was assigned (ID). This command cannot be used in multi systems in the network. ID can be obtained by the command ps. This command ignores completely the state at which the process is it kills the process.<\/p>\n<p><strong>Explain about the command lynx?<br \/>\n<\/strong>This command helps you to browse web from an ordinary terminal. Text can be seen but not the pictures. URL can be assigned as an argument to the G command. Help section can be obtained by pressing H and Q makes the program to quit.<\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Brief about the command nn?<br \/>\n<\/strong>This command allows you to read the news. First you can read about the local news and then the remote news. &#8220;nnl\u201d command makes or allows you to read local news and nnr command is used to read remote news. Manual and help information is available with many popular packages.<\/span><\/p>\n<p><strong>Brief about ftp hostname?<br \/>\n<\/strong>This command lets you download information, documents, etc from a remote ftp. First it is important to configure an FTP for the process to begin. Some of the important commands relevant to the usage of FTP are as follows get, put, mget, mput, etc. If you are planning to transfer files other than ASCII defined it is imperative to use binary mode.<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>Explain about the case statement.<\/strong><br \/>\nThe case statement compares word to the patterns from top to bottom, and performs the commands associated with the first, and only the first, pattern that matches. The patterns are written using the shells pattern matching rules, slightly generalized.<\/span><\/span><\/p>\n<p><strong>Explain the basic forms of each loop?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThere are three loops; for, while and until. For loop is by far the most commonly used form of loop. Basically like other programs it executes a given set of commands and instructions. While and until forms of loop use the exit status from a command based system. They control the execution of the commands in the body of the loop.<\/span><\/p>\n<p><strong>Describe about awk and sed?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe awk program processes this to report the changes in an easier to understand format. Sed output is always behind its input by one line; there is always a line of input that has been processed but not printed, and this would introduce an unwanted delay.<br \/>\n<strong>Explain about signal argument?<br \/>\n<\/strong>The sequence of commands is a single argument, so it must almost always be quoted. The signal numbers are small integers that identify the signal. For example, 2 is the signal generated by pressing the DEL key, and 1 is generated by hanging up the phone. Unless a program has taken explicit action to deal with signals, the signal will terminate it.<\/span><\/p>\n<p><strong>Explain about exec?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nThe exec is just for efficiency, the command would run just as well without it. Exec is a shell built-in that replaces the process running this shell by the named program, thereby saving one process- the shell that would normally wait for the program to complete. Exec could be used at the end of the enhanced cal program when it invokes \/usr\/bin\/cal.<\/span><\/p>\n<p><strong>Explain about trap command<br \/>\n<\/strong>The trap command sequence must explicitly invoke exit, or the shell program will continue to execute after the interrupt. The command sequence will be read twice: once when the trap is set and once when it is invoked. Trap is used sometimes interactively, most often to prevent a program from being killed by the hangup signal.<\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about sort command?<br \/>\n<\/strong>The sort command has an option \u2013o to overwrite a file:<br \/>\n$ sort file1 -0 file2<br \/>\nIs equivalent to<br \/>\n$ sort file1 &gt; file2<br \/>\nIf file 1 and file 2 are the same file, redirection with &gt; will truncate the input file before it is sorted. The \u2013o option works correctly because the input is sorted and saved in a temporary file before the output file is created. Many other commands could also use a \u2013o option.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about the command overwrite?<br \/>\n<\/strong>Overwrite is committed to changing the original file. If the program providing input to overwrite gets an error, its output will be empty and overwrite will dutifully and reliably destroy the argument file. Overwrite could ask for conformation before replacing the file, but making overwrite interactive would negate its efficiency. Overwrite could check that its input is empty.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about kill command?<br \/>\n<\/strong>The kill command only terminates processes specified by process-id when a specific background process needs to be killed, you must usually run ps to find the process-id and then re type it as an argument to kill. Killing process is dangerous and care must be taken to kill the right processes.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about the shell variable IFS?<\/strong><br \/>\nThe shell variable IFS (internal field separator) is a string of characters that separate words in argument lists such as back quotes and for statements. Normally IFS contains a blank, a tab, and a new line, but we can change it to anything useful, such as just a newline.<\/span><\/p>\n<p><strong>Explain about the rules used in overwrite to preserve the arguments to the users command?<br \/>\n<\/strong>Some of the rules are<span style=\"font-family: verdana,geneva;\"><br \/>\n\u2022 $* and $@ expand into the arguments and are rescanned; blanks in arguments will result in multiple arguments.<br \/>\n\u2022 \u201c$*\u201d is a single word composed of all the arguments to the shell file joined together with spaces.<br \/>\n\u2022 \u201c$@\u201d is identical to the arguments received by the shell file: blanks in arguments are ignored and the result is a list of words identical to the original arguments.<\/span><\/p>\n<p><strong>Explain about @@@ lines?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\n@@@ Lines are counted (but not printed), and as long as the count is not greater than the desired version, the editing commands are passed through. Two ed commands are added after those from the history file: $d deletes the single @@@ line that sed left on the current version.<\/span><\/p>\n<p><strong>Explain about vis?<\/strong><span style=\"font-family: verdana,geneva;\"><br \/>\nVis that copied its standard input to its standard output, except that it makes all non printing characters visible by printing them as \\nnn, where nnn is the octal value of the character. Vis is invaluable for detecting strange or unwanted characters that may have crept into files.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Is the function call to exit at the end of vis necessary?<\/strong><br \/>\nThe call to exit at the end of vis is not necessary to make the program work properly, but it ensures that any caller of the program will see a normal exit status from the program when it completes. An alternate way to return status is to leave main with return 0; the return value from main is the program`s exit status.<br \/>\n<\/span><span style=\"font-family: verdana,geneva;\"><br \/>\n<strong>Explain about fgets?<\/strong><\/span><span style=\"font-family: verdana,geneva;\"><br \/>\nFgets (buf, size, fp) fetches the next line of input from fp, up to and including a newline, into buf, and adds a terminating \\0; at most size-1 characters are copied. A Null value is returned at the end of the file.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about efopen page?<br \/>\n<\/strong>The routine efopen encapsulates a vey common operation: try to open a file; if it`s not possible, print an error message and exit. To encourage error messages that identify the offending program, efopen refers to an external string program containing the name of the program, which is set in main.<\/span><\/p>\n<p><span style=\"font-family: verdana,geneva;\"><strong> Explain about yacc parser generator?<br \/>\n<\/strong>Yacc is a parser generator that is a program for converting a grammatical specification of a language like the one above into a parser that will parse statements in the language.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>What is $*?<\/strong><br \/>\nWill display all the commandline arguments that are passed to the script<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\"><strong>Different types of shells?<\/strong><br \/>\nBourne Shell (bash)<br \/>\nKorn Shell (ksh)<br \/>\nC Shell (csh)<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: small;\"><span style=\"font-family: verdana,geneva;\">What\u00a0 is difference between a wild-card and regular expression?<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interview Questions Sets : Shell Script Descriptive Questions Sets What is shell scripting? Shell scripting is used to program command line of an operating system. Shell Scripting is also used to program the shell which is the base for any operating system. Shell scripts often refer to programming UNIX. Shell scripting is mostly used to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4303,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[52],"tags":[641,3969,766,3968,3961,507,1553,482,1830,3910,138,3046,3960,3970,3966,3965,3964,3963,3967,3962,637],"class_list":["post-243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions-answers","tag-answers","tag-descriptive-shell-script-interview-question-and-answers","tag-interview","tag-interview-questions-answer-for-shell-script","tag-interview-questions-sets","tag-list","tag-most-asked","tag-questions","tag-selected","tag-sets","tag-shell","tag-shell-script","tag-shell-script-descriptive","tag-shell-script-descriptive-interview-question-and-answers","tag-shell-script-interview-guide","tag-shell-script-interview-qa","tag-shell-script-interview-questions-answers","tag-shell-script-job-interview","tag-shell-script-job-interview-kit","tag-shell-scripting-interview","tag-top"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":32354,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/243\/revisions\/32354"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4303"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}