资源描述
Course materials may not be reproduced in whole or in part without the prior written permission of IBM.5.04.1 Copyright IBM Corporation 2008 Unit 10Processes Copyright IBM Corporation 2008Unit ObjectivesAfter completing this unit,you should be able to:Define an AIX processDescribe the relationship between parent and child processesCreate and invoke shell scripts Copyright IBM Corporation 2008The Process EnvironmentProgramUser and group IDData Process ID(PID)Open filesParent Process ID(PPID)Current directoryProgram variables What Is a Process?lEach program runs in a process:lThe variable$shows the process ID of the current shell:$echo$4712lThe ps command shows the running processes:$ps-u team01 Copyright IBM Corporation 2008login:AIX SystemPID=202 -kshlogin:johnJohns Password:xxxxxx$_Environmentprogram/usr/bin/kshuidjohngidstafffiles/dev/tty1PID202Login Process Environment Copyright IBM Corporation 2008AIX System$cat kfileEnvironment during executionprogram/usr/bin/catuidjohngidstafffiles/dev/tty1 kfileparent -kshPID310PPID202PID=202 -kshPID=310 catProcess Environment Copyright IBM Corporation 2008$echo$202$ksh (Create a subshell)$echo$206$date(Run a command)Tue Jan 4 11:18:26 GMT 2000$(Exit the subshell)$echo$202 Subshell PID PPID -ksh 202 1 ksh 206 202 date 208 206Parents and Children Copyright IBM Corporation 2008$x=4$ksh$echo$x$x=1$echo$x4 Subshell Variables and Processes Variables are part of the process environment.Processes cannot access or change variables from another process.Copyright IBM Corporation 2008variableShellSubshellexport variable=valueActivity:Exporting Variables Copyright IBM Corporation 2008A shell script is a collection of commands stored in a text file$vi hello echo Hello,John.Today is:$(date)pwd ls:wq$What Is a Shell Script?Copyright IBM Corporation 2008$cat helloecho Hello,John.Today is:$(date)(1)pwd(2)ls(3)$ksh helloHello,John:Today is:Wed Sep 13 19:34(1)/home/john(2)books letter1 text2sarah(3)$_-ksh$ksh hellokshscript commands Subshell Invoking Shell Scripts(1 of 3)Copyright IBM Corporation 2008The shell uses the PATH variable to find executable programs.$cat helloecho Hello,John.Today is:$(date)(1)pwd(2)ls(3)$chmod+x hello$helloHello,John:Today is:Wed Sep 13 19:34(1)/home/john(2)books letter1 text2sarah(3)$_ Subshell Invoking Shell Scripts(2 of 3)Copyright IBM Corporation 2008$cat set_dirdir1=/tmp dir2=/usr$.set_dir$echo$dir1/tmp$echo$dir2/usr.(dot):Execution in the current shell?What is the value of dir1 and dir2,if set_dir is called without the dot?Invoking Shell Scripts(3 of 3)Copyright IBM Corporation 2008Exit Codes from CommandslA command returns an exit value to the parent process:0=Success 1-255=Other than successfullThe environment variable$?contains the exit value of the last command:$cd/etc/securityksh:/etc/security:Permission denied$echo$?1 Copyright IBM Corporation 2008Checkpoint1.When would you execute a shell script using the dot(.)notation?Why?2.What is the command that is used to carry down the value of a variable into the subshell?3.What would be the value of x at the end of the following steps?$(.login shell.)$ksh$x=50$export x$(what is the value of x set to now?)Copyright IBM Corporation 2008Checkpoint Solutions1.When would you execute a shell script using the dot(.)notation?Why?When you are using the script to change variable values in the current shell.2.What is the command that is used to carry down the value of a variable into the subshell?export variable_name3.What would be the value of x at the end of the following steps?$(.login shell.)$ksh$x=50$export x$(what is the value of x set to now?)x would have the value it had before starting the subshell.If the login shell had not set the variable,then after return from the subshell it would still not be set.Copyright IBM Corporation 2008ShellScriptsActivity:Shell Scripts Copyright IBM Corporation 2008Unit SummaryShell scripts can be invoked in three ways:$ksh scriptname(must have read permission)$scriptname(must have read and execute permission)$.scriptname(must have read permission)Each program runs in an AIX process.Every process has an environment in which it runs much of which is inherited from its initiating process,the parent process.
展开阅读全文