exam Flashcards
In bash what is the function of the following commands and symbols:
sed
SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening them, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it.
SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution).
SED command in unix supports regular expression which allows it perform complex pattern matching.
In bash what is the function of the following commands and symbols:
»
> > is used to append to a file
In bash what is the function of the following commands and symbols:
|
Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command’s output may act as input to the next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes
grep
The grep command searches for the pattern specified by the Pattern parameter and writes each matching line to standard output. The patterns are limited regular expressions in the style of the ed or egrep command. The grep command uses a compact non-deterministic algorithm.
$2
./script.sh Hello World
$0 = ./script.sh
$1 = Hello
$2 = World
echo
In computing, echo is a command that outputs the strings that are passed to it as arguments. It is a command available in various operating system shells and typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.
#
comment
$@
$@ refers to all of a shell script’s command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them
ls
In computing, ls is a command to list computer files and directories in Unix and Unix-like operating systems.
cat
Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives their content as output. It helps us to create, view, concatenate files
cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to catenate files. It has been ported to a number of operating systems.
cd
The cd command, also known as chdir, is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files
list all text files in a directory
find . -name ‘*.txt’
list the contents of a user’s home directory
ls ~
print the last 10 lines of a file called animals.txt
tail -10 foo.txt
perform a case-sensitive search of a file called products.txt for all lines
starting with the letter P
grep “^p” foo.txt
perform a case-insensitive search of a file called products.txt for all lines
ending with the letter p
grep -i “p$” foo.txt
list the contents of a parent directory and save the output into a file called
parent.txt
ls ..»_space; bar.txt
print out the contents of a file called names.txt with line numbers
cat -n bar.txt
list the contents of a folder and save it to a file called list.txt
ls ../exam_prep»_space; bar.txt
List 5 responsibilities of an operating system
Process management.
Inter-process communication (IPC) and networking.
I/O and file systems.
Memory management.
Thread-support.
Security, i.e. safeguarding stability and system access.
An operating system provides two interfaces, what are these interfaces and describe
in your own words their differences
OSes have two primary interfaces, the hardware interface and the software interface.
Applications talk to the operating system by invoking the system services it provides.
This is called system interface programming i.e. writing code that makes system calls using the software interface.
The hardware interface is where the operating system meets the hardware and carries out input and output (I/O) for the user.
What is the role of the system service interface and how is it accessed?
System Calls
A system call, or syscall, is a request made to the kernel for access to a resource.
Compilers translate high-level language I/O requests into read and write system calls.
System services are what we can ask of the operating system and sometimes referred to as the software instruction set.
Assembly instructions define interaction with the CPU.
There are six categories of system call.
System Call Categories
Process control.
File management.
Device management.
Information maintenance.
Communication.
Protection.
kernel
Briefly describe the role of interrupt driven I/O within the context of operating
systems and describe how it functions.
The three types of interrupt are:
Software, generated by system calls, discussed above.
Hardware, generated by external devices.
Exceptions, generated by the CPU when errors happen.
Interrupts allow the OS to maintain control.
CPU processes instructions one at a time. The OS must be able to retake control from another process.
Interrupts alert the OS to a process requiring attention.
Interrupt-Driven I/O
In this case, when a device needs attention:
It alerts the CPU with an interrupt.
The CPU finishes executing the current instruction.
The CPU saves its current context.
The CPU asks the interrupting device to identify itself and acknowledges the interrupt so that the device can stop interrupting.
The CPU runs the interrupt service routine of the corresponding device.
The saved context is restored and the CPU continues from where it left off before being interrupted.
Interrupt line to CPU from device
|
–>CPU Main Memory
| | |
| ——————
| |
| Data Bus
| |
| Status / Data
| |
—- Device (e.g. Disk)
What is a process? Describe what it is in plain language, with some detail. From a Linux/Unix perspective, how is a process created and what is its lifecycle?
A process is a running program and all the things it needs to run. There could be many copies of the same program running, i.e. multiple processes.
A program is a static thing - a list of written instructions.
When a program is launched the operating system sets up the environment in which that program will run i.e. it provides the address space in which the program will execute.
Once an address space is set up program execution can begin.
You can think of the process address space as a box in memory to which the process is confined during its lifetime.
A process is the combination of the address space and the activity (or thread) of execution.
Process Life Cycle States
A process can be in one of five life-cycle states.
New: the process is being created but not yet runnable/ready.
Runnable / Ready: the process has all it needs to run, waiting for time on the CPU.
Running: the CPU is running the process program right now.
Waiting / blocked: the program is waiting for some resource, e.g. on data, for a time period to elapse, for a child process to return.
Exit: the process has finished.
Other state models exist.