1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty...
-
Upload
sabina-knight -
Category
Documents
-
view
213 -
download
0
Transcript of 1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty...
1Logging in to a UNIX Systeminit (Process ID 1 created by the kernel at bootstrap)
spawns getty for every terminal device
invokes our login shell
terminaldevice driver
user at a terminal
fd 0, 1, 2
login reads password entry (getpwnam()), asks for user's password (getpass()) and validates it; changes ownership of our terminal device, changes to our UID and changes to our home directory. Sets additional environment variables (HOME, SHELL, USER, LOGNAME, PATH)
fd 0, 1, 2
Login shell (bash)fd
0, 1
, 2
getty opens terminal device, sets file descriptors 0, 1, 2 to it, waits for a user name, usually sets some environment variable (TERM)
invokes login when user name entered
1Command Execution
current shell (bash)
executes built-in commands(echo, kill, pwd,...) orshell scripts invoked by the . (dot) command: . shell-script
sub-shell (bash) executes a shell script or calls exec() to execute a program
variables defined in the parent are not passed (use the export command in parent to pass variables). Variables defined or changed in a sub-shell does not affect variables of the parent !
fork() (creates a new shell process)
wait
or
continue if command isexecuted in the background
sub-shell terminates after script orprogram execution
1
stack (caller info., return address,
local variables)(read/write)
Typical Memory Layout
text (code & constants, read only)
command-line arguments, environment variables
initialized
uninitialized
Heap(dynamic memory allocation)
data(read/write)
char a, *p="string";int v[10];
int f(char c){
int x, y;static long i=1;...return x;
}
}read from program file
}initialized to 0
x, y, c
p, i
a, v
"string", f
Low address
1
User process
Starting and Terminating a C Program
UNIX kernel
Program file
C start-uproutine
main()
call
user functions
call
returnreturn
exit()does not return
standard I/Ocleanup
call
retu
rn
_exit()
_exit()
_exit()
exec - the only way a program is executed by the kernel
1
current processsigprocmask()
kernel
user interrupt (CTRL-C)
sigpending()
kill()
raise(), abort()
process
Signal Mask, Pending SignalsEach process has a signal mask:
set of signals currently blocked from delivery to the processsignal mask can be manipulated by sigprocmask()
if set is not NULL => signal mask is modified depending on the value of howif oset is not NULL => current signal mask is returned
sigpending() returns the set of signals that are blocked and currently pending for the processsigset_t is a data type to represent a signal set.
int sigprocmask(int how,sigset_t *set, sigset_t *oset) int sigpending(sigset_t *set)