USP
UNIT – 3SHELLQ1) What do u mean by Shell?A1) A shell is a program that sits on the kernel and acts as an agent or interface between the users and the kernel and hence the hardware. It is similar to the command.com in the MS-DOS environment. A shell is a command interpreter or a processor. Q2) What are the different types of Shells available?A2)There are different types of shells available. Some of them are discussed here: Bourne shell (sh): This is the most common shell available on UNIX system and the first major shell to be developed. This shell is widely used. It has been named after its author, Stephen Bourne at AT&T Bell labs. This shell is distributed as standard shell on almost all Unix system. 2. C shell (csh): Bill Joy developed this shell at UCB (University of California, Berkeley) in 1978 as a part of the BSD release. It is called as C shell because its syntax and usage is very similar to the C programming language. Unfortunately this shell is not available on all machines. Shell scripts written in the C shell are not compatible with the bourne shell. One of the major disadvantage of C shell over the bourne shell is its capability to execute processes in the background. 3. Korn shell (ksh): This shell is developed by David. Korn at AT&T Bell labs. It is built on Bourne Shell. It also incorporate certain features of the C shell. It is one of the widely used shells. It can run bourne shell scripts without any modifications 4. Bourne Again shell (bash): This shell was developed by B. Fox and C Ramey at free software foundation. Certain Linux operating system variants come with this shell as its default shell.
Q3) Write the features of Korn Shell?A3)Features of Korn Shell are as follows:● Interactive exiting of command line.● Better function definitions. ● Extensive pattern matching Several features adopted from C shell are :● Command History. ● Job control & their moving from background to foreground. ● Aliases for abbreviated command names● Field (~) sign used as short hand for name of home directory
Q4) Write the features of C Shell?A4) Features of C shell are as follows:● Input & Output redirection● Wildcards & meta characters for filename abbreviation● Set of shell variables to customize your environment● Integer Arithmetic● A History mechanism allowing you to recall previous command● Aliasing your abbreviation used frequently without a shell script● More flexible form of command substitution● Job Control, i.e, Ability to switch between several processes and control their progress● A built in set of operators based on 'C for writing shell scripts. Q5)What are the different types of Shell Options?A5) There are number of options available which are used in different shells: Global (noglob): The global option controls the expansion of wildcard tokens in a command. For example, when the global option is off, the list file (ls) command uses wildcards to match the files in a directory. Thus, the following command lists all files that start with the 'file' followed by one character: $ Is file?On the other hand, when the global option is on, wildcards become text characters and are not expanded. In this case, only the file named file? would be listed. 2. Print Commands (verbose and xtrace): There are two print options, verbose and xtrace that are used to print commands before they are executed. The verbose option prints the command before it is executed. The xtrace option expands the command arguments before it prints the command. 3. Command-Line Editor (vi and emacs): To specify that the emacs editor is to be used in the Kom shell, we turn on the emacs option. To specify that the vi editor is to be used in the Korn shell, we turn on the vi option. These options are valid only in the Korn shell. 4. Ignore End of File (ignoreeof): Normally, if end of file (ctrl+d) is entered at the command line, the shell terminates. To disable this action, we can turn on the ignore end of file option, ignoreeof. With this option, end of file generates an error message rather than terminating the shell. 5. No Clobber Redirection (noclobber): When output or errors are directed to a file that already exists, the current file is deleted and replaced by a new file. To prevent this action, we set the noclobber option.
Q6) What do you mean by process ID or pid?A6) The operating system tracks processes through a five digit ID number known as the pid or process ID. Each process in the system has a unique pid. Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any one time, no two processes with the same pid exist in the system because it is the pid that UNIX uses to track each process.
Q7) What are the methods that UNIX uses to track the process? A7) (i) Starting a Process: There are two ways:(a) Foreground Processes(b) Background Processes(a) Foreground Processes: By default every process that we start runs in the foreground. It gets its input from the keyboard and sends its output to the Screen.We can see this happen with the Is command. If we want to list all the files in my current directory, we can use the following command:$ls ch*.docThis would display all the files whose name start with ch and ends with doc: ch01-1.doc ch010.doc ch02.doc ch03-2.docch04-1.doc ch040.doc ch05.doc ch06-2.docch01-2. doc ch02-1.docThe process runs in the foreground, the output is directed to my screen, and if the ls command wants any input (which it does not), it waits for it from the keyboardWhile a program is running in foreground and taking much time, we cannot run any other commands (start any other processes) because prompt would not be available until program finishes its processing and comes out. (b) Background Processes: A background process runs without being connected to our keyboard. If the background process requires any keyboard input, it waits. The advantage of running a process in the background is that we can run other commands; we do not have to wait until it completes to start another! The simplest way to start a background process is to add an ampersand ( &) at the end of the command.$ls ch*.doc &This would also display all the files whose name start with ch and ends with .doc:ch01-1.doc ch010.doc ch02.doc ch03-2.doc ch04-1.doc ch040.doc ch05.doc ch06-2.docch01-2.dọc ch02-1.docHere if the ls command wants any input (which it does not), it goes into a stop state until we move it into the foreground and give it the data from the keyboard. That first line contains information about the background process - the job number and process ID. We need to know the job number to manipulate it between background and foreground.If enter is pressed, then we get[1] + Done Is ch*.doc &$The first line tells we that the ls command background process finishes successfully. The second is a prompt for another command,(ii) Listing Running Processes: It is easy to see our own processes by running the ps (process status) command as follows:$psPID TTY TIME CMD 18358 ttyp3 00:00:00 sh18361 ttyp3 00:01:31 abiwordTTY ttyp3 00:00:00 psOne of the most commonly used flags for ps is the-f (f for full) option, which provides more information as shown in the following example --$ps -fUID PID PPID C STIME TTY TIME CMDamrood 6738 3662 0 10:23:03 pts/6 0:00 first_oneamrood 6739 3662 0 10:22:54 pts/6 0:00 second_oneamrood 3662 3657 0 08:10:53 pts/6 0:00 -kshamrood 6892 3662 4 10:51:50 pts/6 0:00 ps-fHere is the description of all the fields displayed by ps -f command: Column DescriptionUID User ID that this process belongs to (the person running it).PID Process IDPPID Parent process ID (the ID of the process that started it).C CPU utilization of process.STIME Process start time.TTY Terminal type associated with the processTIME CPU time taken by the process.CMD The command that started this process.here are other options which can be used along with ps command :Option Description-a Shows information about all users-x Shows information about processes without terminals.-u Shows additional information like -f option.-e Display extended information, (iii) Stopping Processes:Ending a process can be done in several different ways. Often, from a console based command, sending a CTRL + C keystroke the default interrupt character) will exit the command. This works when process is running in foreground mode.If a process is running in background mode the first we would need to get its Job ID using ps command and after that we can use kill command to kill the process as follows:$ps –f UID PID PPID C STIME TTY TIME CMDamrood 6738 3662 0 10:23:03 pts/6 0:00 first_oneamrood 6739 3662 0 10:22:54 pts/6 0:00 second_oneamrood 3662 3657 0 08:10:53 pts/6 0:00 -kshamrood 6892 3662 4 10:51:50 pts/6 0:00 ps-f$kill 6738TerminatedHere kill command would terminate first_one process. If a process ignores a regular kill command, you can use kill -9 followed by the process ID as follows -$kill -9 6738Terminated(iv) Parent and Child Processes:Each unix process has two ID numbers assigned to it: Process ID (pid) and Parent process ID (ppid). Each user process in the system has a parent process.Most of the commands that we run have the shell as their parent. Check ps-f example where this command listed both process ID and parent process ID Q8) How do we customize our shell environment?A8)Customization process: UNIX allows us to customize the shells and the environment we use. When we customize the environment, we can extend it to include subshells and programs that we create. Depending on how we establish them, they can be temporary or permanent. .Temporary Customization: Temporary customization can be used to change the shell environment and configuration for the complete current session or for only part of a session. Normally we customize our environment for only a part of the session, such as when we are working on something special. For example, if we are writing a script, it is handy to see the expanded commands as they are executed. We would do this by turning on the verbose option. When we are through writing the script, we should turn off the verbose option. Any option changed during the session is automatically reset to its default when we log on the next time 2. Permanent Customization: Permanent customization is achieved through startup and shutdown files. Startup files are system files that are used to customize the environment when a shell begins. We can add customization commands and set customization variables by adding commands to the startup file. Shutdown files are executed at logout time. Just like the startup files, we can add commands to clean up the environment when we log out. The korn shell, bash shell and c shell uses different types of startup and shutdown file which is described as below:
Q9) What are the different profile files used by the korn shell?A9) The Korn Shell uses the three profile files :(i) System Profile File: There is one system-level profile file, which is stored in the /etc directory. Maintained by the system administrator, it contains general commands and variable settings that are applied to every user of the system at login time. The system profile file is generally quite large and contains many advanced commands. The system profile is a read only file; its permissions are set so that only the system administrator can change it.(ii) Personal Profile File: The personal profile. - profile, contains commands that are used to customize the startup shell. It is an optional file that is run immediately after the system profile file. Although it is a user file, it is often created by the system administrator to customize a new user's shell. If we make changes to it, we should make a backup copy and make changes to it. (iii) Environment File: In addition, the Korn shell has an environmental file that is run whenever a new shell is started. It contains environmental variables that are to be exported to subshells and programs that run under the shell. Because it is executed each time a new shell is started, it is recommended that it be kept short.
Q10) Describe the login and logout files used by C Shell.A10) (i) Login File: The C shell login file (~/.login) is the equivalent of the Korn and Bash user profile file. It contains commands and variables that are executed when the user logs in. It is not exported to other shells nor is it executed if the C shell is started from another shell as a subshell.(ii) Logout File: The C shell logout file, ~/.logout is run when we log out of the C shell. It contains commands and programs that are to be run at logout time. For example, it is the ideal place to store a script that automatically backs up critical files.
0 matching results found