Linux Operating System Flashcards
What is Linux distribution?
The term Linux is commonly used to mean the kernel plus set of software tools and libraries that together make a complete operating system.
In early days of Linux, the user has to assemble all of these software, create file system and correctly place & configure all the software on a system. This demanded considerable time and expertise. As a result, market opened for Linux distributor, who created packages (distributions) to automate most of the installation process, creating a file system and installing the kernel and other required software.
What is FIPS?
“Federal Information Processing Standard” is the name of set of standards specified by the USA government for the purchase of its computer systems
What is universality of I/O?
The kernel provides just one type of file - “A sequential stream of bytes”. Same set of system calls (open, read, write, close) are used to perform I/O on all types of files including devices. In UNIX systems, there is no end-of-file character. The end-of-file is detecte3d by read that returns no data.
This is called as universality of I/O
What is a kernel thread?
A kernel thread is an execution context that can be independently scheduled, it may be associated with a user program or it may run only some kernel functions. Linux uses kernel threads in a very limited way to execute a few kernel functions periodically.
What is a file name and hard-link?
A filename included in a directory is called a file hard-link. The same file can have several hard links included in the same directory or different directory i..e it may have several filenames. “ln” command is used to create a hard link
$ ln P1 P2
Hard links cannot be created for directories and can be created only among the files included in the same FS.
What is a symbolic link?
Symbolic link is a short file that contains an arbitrary pathname of another file.
$ln -s P1 P2
What information is stored in i-node?
- File type (regular/directory etc.)
- No of hard links associated with the file
- File length in bytes
4 Device-id (ID of device which contains the file) - i-node number
- UID of file owner
- GID of the group that owns the file
- Several time-stamps including change time.
- Access rights and file mode
What is the meaning of reentrant kernel?
All UNIX kernels re reentrant. This means that several processes may be executing in the kernel mode at the same time.
One way to achieve reentrancy is to write functions so that they modify only local variables and do not alter global data structures. Such functions are called reentrant functions.
What is kernel control path?
Kernel control path denotes the sequence of instructions executed by kernel to handle a system call, an exception or an interrupt. Each process runs in its ow private address space which includes private stack, data and code areas.
What is a race condition?
When the outcome of a computation depends on how two or more processes are scheduled, the code is incorrect. This is called ‘race condition’
What is a Semaphore?
A semaphore s simply a counter associated with a data structure. It is checked by kernel thread before it tries to access the data structure. Each semaphore may be viewed as an object composed of -
- An integer value
- A list of waiting processes
- Two atomic operations: up and down
The down method decreases the value of semaphore. If the new value is less than 0 (zero), the method adds running process to the semaphore list and then blocks (i.e. invokes the scheduler). The up method increases the value of the semaphore and if its new value is greater than or equal to zero, reactivates one or more processes in the semaphore list.
What is a system call and how is it executed?
A ‘system call’ is a controlled entry point into the kernel allowing a process to request that kernel perform some action on the process’s behalf. A system changes the processor state from user mode to kernel mode when a system call is invoked. The set of system calls is fixed and each system call is identified by a unique number.
Steps involved in a system call execution -
- Application makes a system call by invoking a wrapper function in the ‘c’ library.
- Wrapper function copies the arguments passed to it in the specific registers since kernel expects it that way.
- Since all system calls enter the kernel in the same way, the kernel needs some method of identifying the system call. For this, each system call is given a number and wrapper function copies it into a specific CPU register (%EAX)
- Wrapper function executes a trap machine instruction (int x80) which causes the processor to switch from user mode to kernel mode and execute the trap instruction.
- In response to trap, the kernel invokes its system call routine to handle the trap.
- Kernel saves register values on kernel stack and checks validity of system call number
- kernel invokes appropriate system call service routine, which is found in sys_call_table. The service routine performs the required tasks. Finally service routine returns a result status to the system_call routine.
- Restores register values from kernel stack and places the system call return value on the stack.
- Returns to wrapper function, simultaneously returning the processor to user mode.
What is the use of ioctl() system call
Most of the file systems are accessed using universal I/O model which includes four system calls (open, read, write and close). When access to specific feature of the file system or device is required, a program can use ‘catchall’ ioctl() system call which proves an interface to features that fall outside the universal I/O model.
How to create a sparse file on Linux?
using lseek() API call
Using lseek you can write past end of file. The space in between previous end of file and new end of file is referred as file hole. From programming point of view, bytes in the hole exists and reading from the hole returns a buffer of bytes containing 0 (null bytes). File holes does not take up any disk space. Such a file is called sparse file.
Another way is to use truncate() system call. It sets the size of the file to the value specified by length. If the file is longer than the length then excess data is lost. If file is shorter, it is extended by padding with sequence of null bytes or hole.
What is the use of fcntl() system call?
It performs a range of control operations on an open file descriptor. For example - retrieve or modify the access mode and open file status flags of an already open file.