Saturday, December 29, 2012

Unix Shells by Example

The wait System Call. The parent shell is programmed to go to sleep (wait) while the child takes care of
details such as handling redirection, pipes, and background processing. The wait system call causes the parent
process to suspend until one of its children terminates. If wait is successful, it returns the PID of the child that
died and the child's exit status. If the parent does not wait and the child exits, the child is put in a zombie state
(suspended animation) and will stay in that state until either the parent calls wait or the parent dies.[3] If the
parent dies before the child, the init process adopts any orphaned zombie process. The wait system call, then,
is not just used to put a parent to sleep, but also to ensure that the process terminates properly.

The exit System Call. A new program can terminate at any time by executing the exit call. When a child
process terminates, it sends a signal (sigchild) and waits for the parent to accept its exit status. The exit status
is a number between 0 and 255. An exit status of zero indicates that the program executed successfully, and a
nonzero exit status means that the program failed in some way.

Initially, the umask is 000, giving a directory 777 (rwxrwxrwx) permissions and a file 666 (rw–rw–rw–)
permissions as the default. On most systems, the umask is assigned a value of 022 by the /bin/login program
or the /etc/profile initialization file.
The umask value is subtracted from the default settings for both the directory and file permissions as follows:
777 (Directory) 666 (File)
–022 (umask value) –022 (umask value)
−−−−−−− −−−−−−−−−
755 644
Result: drwxr−xr−x −rw−r−−r−−

find / −name file −print 2> errors
Any errors from the find command are redirected to errors. Output goes to the terminal.
(The Bourne and Korn shells redirect errors this way.)

No comments:

Post a Comment