UNIX_All_Units_Answers
UNIX_All_Units_Answers
UNIX_All_Units_Answers
UNIT 1
File permissions are displayed as a set of characters (e.g., `-rw-r--r--`) that indicate:
1. Read (r): Allows reading the file.
2. Write (w): Allows modifying the file.
3. Execute (x): Allows executing the file as a program.
4. Write about grep, regular expressions, and awk in UNIX.
grep: A command-line utility to search for patterns in files. Example: `grep 'pattern' file.txt`.
Regular Expressions: Patterns used for matching text. Example: `[a-z]+` matches lowercase
words.
awk: A programming language for pattern scanning and processing. Example: `awk '{print
$1}' file.txt`.
Shell Programming: Writing scripts in shell languages to automate tasks. Example: Creating
a shell script to back up files.
UNIT 2
1. What is the UNIX model? Explain about signals and process control.
The UNIX model is based on a simple design philosophy: 'Everything is a file.' It uses a
hierarchical file system and allows for processes and devices to be treated as files, making
the system consistent and flexible.
Signals: Signals are software interrupts used to communicate with processes. Examples
include `SIGINT` (interrupt signal) and `SIGKILL` (terminate signal). Signals can be sent
using the `kill` command or system calls.
Process Control: UNIX provides system calls like `fork()`, `exec()`, and `wait()` to create and
manage processes. `fork()` creates a new process, `exec()` replaces the current process with
a new one, and `wait()` pauses the parent process until the child process finishes.
Features of Daemons:
1. Run in the background.
2. Do not have a controlling terminal.
3. Start at system boot and continue running until shutdown.
3. What is interprocess communication? Explain file and record locking.
Interprocess Communication (IPC) allows processes to exchange data and synchronize their
actions. IPC methods include pipes, message queues, shared memory, and semaphores.
File and Record Locking: Prevents simultaneous access to files or specific parts of files by
multiple processes.
1. File Locking: Locks the entire file.
2. Record Locking: Locks specific parts (records) of a file for finer control.
Shared Memory: Fast IPC mechanism that allows multiple processes to access the same
memory space. Created and managed using `shmget()`, `shmat()`, and `shmdt()`.
Messages refer to structured data units exchanged between processes using message
queues or other IPC mechanisms.
UNIT 3
Socket Address: Consists of an IP address and port number, which uniquely identifies a
socket.
Types of Sockets:
1. Stream Sockets (TCP): Reliable and connection-oriented.
2. Datagram Sockets (UDP): Unreliable but faster, connectionless.