Question: Q1. Hint: Commands to study to answer this question: grep, wc, echo, pipe ( | ), ps, process states, and man pages for ps options
Q1. Hint: Commands to study to answer this question: grep, wc, echo, pipe ( | ), ps, process states, and man pages for ps options NOTE: Use man command before you start answering this question and before issuing script command to find the options to use with the ps command to find the answers in this question as well as to find the characters representing the various states of a process. 1) Issue appropriate command to display your processes, that is, processes for which you are the owner 2) Display information about your processes using long option 3) Examine the output of the previous command and with echo command, display the name (command name) and the state character for your shell process and the meaning of the state character. You have to look at the man pages for the ps command to see the meaning of the process state character before doing this question when the script is not in effect. Never issue man command when script command is in effect. 4) Using echo command, answer the process id (pid) of the shell process and the parent pid of your shell process 5) Display all the processes in the system using an appropriate option other than long option Pipe takes the standard output of the command preceding it and feeds to standard input of the command following it. The pipe is indicated by | character between the commands as Command1 | Command2 The grep command can be used to search for a string in one or more files. When the line with the string is found, it is displayed. The wc command can be used to find the number of lines, number of words and number of character in a file or the input supplied to it. Using grep and pipe do the following: 6) Issue appropriate command to display all the processes in the system and pipe the output to the grep command to display the line containing the init process. 7) Using the echo command answer the process ID (pid) of the init process. Q2. Hint: Commands to study to answer this question: predefined shell variables, and .profile script file, echo SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME. Do not give just the value of the shell variable as answer to questions given below. 1) Display the value of SHELL 2) SHELL contains the pathname of the shell program you are using. With echo command, answer what is the name of the shell program 3) Display the value of HOME 4) With echo command, answer what the HOME value stand for 5) Display the value of PATH 6) PATH contains the list of directories shell searches for the nonbuilt-in command (that is, the executable program file with name same as the command you typed). The directories in the list are separated by : character. With echo command, answer whether the list contains . (dot or period) and whether the shell searches the current working directory. 7) Display the value of MAIL 8) With echo command, answer where the system stores your emails. Indicate whether it is a directory or file. 9) Display the value of TERM 10) With echo command, answer what is the type of the terminal you are using. Note: The combination of keyboard and monitor is called a terminal. If the value of TERM is xterm, then indicate what xterm stands for. Do not give the answer as xterm. 11) The .profile file is in your login directory. It is a startup shell script file containing shell (UNIX) commands. The system executes the UNIX shell commands in this file each time you login to setup your session environment before shell displays the first shell prompt (which is $ by default). Display the content of .profile file 12) With echo command specify the list of predefined shell variables in the .profile file Q3. Scripting with if statement: Commands to study to answer this question: sleep, ps, kill, echo, cat, creating your own shell variable, if statement, and two-character shell variable $! and $? 1) Exit from script, if is currently enabled; if it is not enabled, skip this item (1) 2) Using the vi editor, create a shell script file to do the following: a) Issue sleep 1500 & command to run it as a background process. b) The two-character shell variable $! contains the process ID (pid) of the above sleep process running in the background. Display the content of the variable $!. c) Issue ps command to see that the sleep process is running. d) Store the sleep process ID (pid) in a user defined (your own) shell variable e) Issue cat command with a filename that does not exist f) The two character shell variable, $? Contains the completion status of the previous cat command. Using an if statement, check the completion status of the above cat command by checking the value of $?. If cat command is successful, then echo cat command completed successfully else echo cat command failed. g) Kill the background process with pid stored in your shell variable above as the argument to kill command h) Issue ps command to see that the background process is terminated. i) Echo, the script is done using echo command 3) Issue script command to capture the output of the items below 4) Add execute permission to the file 5) Display the attributes of the script file 6) Display the content of the script file 7) Run the script file by typing the name of the script file. NOTE: You must submit both the content of the shell script file and the output generated by running the script.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
