|
|
səhifə | 5/5 | tarix | 10.05.2022 | ölçüsü | 316,35 Kb. | | #57309 |
| Unix
Special Files - Unique feature of UNIX
- Integral to I/O devices
- Acts as ordinary file
- Read/Write requests activate device
- File and device I/O treated similar as possible
- Same syntax and meaning
- Same protection
Processes and Images - Image – execution environment
- Core Image
- Register Values
- Open Files
- Curr. Directory
- Curr. state
Processes - Execution of image
- Image resides in core
- pID = fork(label)
- Splits into two processes
- Contain original image
- Parent/child processes
- Parent Process
- Control returns from fork
- Child Process
Pipes - filep = pipe()
- Returns file descriptor
- Creates interprocess channel
- Passed from parent to child through fork
- Read/Write
- Read waits, data transferred
- Setup by common ancestor of processes
Execution of Programs - execute(file, arg1, arg2, …, arg-n)
- arg1 usually same as file
- Read in/execute
- Creates process
- Only returns on error
- “jump” instead of subroutine
Process Synchronization - processid = wait()
- Suspend execution
- Wait for child process
- Error if no children
- Can contain status from further descendants
Termination - exit(status)
- Terminates process
- Destroys image
- Closes open files
- “Obliterates”
- Returns to parent or higher
The Shell - Aids in communication with UNIX
- Command line interpreter
- Delimit to strings, search for command
- If command not found:
Standard I/O - Open file
- Descriptor 1 – typewriter, write to 1
- Descriptor 0 – Read from 0
- Can use “>” and “<“
- “>” print/out to file after
- “<“ read/in from file after
- ls > there
- ed < script
- Interpreted directly by the Shell
Filters - Commands can direct to each other
- Simplifies commands to the Shell
- Makes commands look less “clumsy”
- Filter – copies standard input to standard output with processing
- Character transliteration, sorting of input, encryption/decryption
Command Separators: Multitasking - Provided by the Shell
- Commands separated by ;
- Commands followed by & do not wait for termination
- Use parenthesis for order of operations
- (date ; ls) > x &
Shell as Command: Command Files - Shell is a command
- Can be called recursively
- File contains following lines:
as source mv a.out testprog testprog - Command sh < filename
- Can also substitute parameters
Implementation of the Shell - Shell mostly waits for user input
- New-line character causes read to return
- Read broken down into form capable of execute
- fork() called
- Child process attempts to execute with arguments
- Parent waits for child to die
Command is finished. Shell waits for next command - Main loop of Shell never terminates
Initialization - Instances of Shell that user sees are child processes
- UNIX creates process of init on startup
- 1 for keyboard, 0 for printer file descriptions
- Creates Shell when user logs in
- When Shell executes, init waits
Other Programs as Shell - User’s entry in password file can contain name of program
- Programs can be executed at login
- Can immediately begin working
- User’s can be prevented from invoking programs
- Limit users to ONLY single program
- Ex: Chess
Log in as player, only play game Traps - Programs stuck in loop can be terminated
- Interrupt signal
- “delete” character
- Cease execution, do not produce core image file
- Quit signal
- Force core image to be created
- Shell ignores quits
- Prevent user from being logged out by quit
Perspective - UNIX was not created to meet any needs
- Creators dissatisfied
- Created more “hospitable” environment for PDP-7
- Written to easily write, test, run programs
- System was able to maintain itself
- Easily modified to fit new ideas/technology
Influences - Success of UNIX comes from exploitation of specific ideas
- Examples include
- Fork operation from Berkely
- I/O System calls from Multics
- Shell name and function from Multics
Dostları ilə paylaş: |
|
|