LINUX

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

i. What programming language is being used? ii. How are the processes being created?

i. The programming language being used is C. This can be inferred from the file extension
".c" and the use of standard C library headers such as <stdio.h>, <stdlib.h>, and <unistd.h>.
ii. The processes are being created using the fork() system call. The fork() function creates a
new process by duplicating the calling process. After the fork() call, both the parent and child
processes will have copies of the code that follows the fork() call. The value returned by
fork() determines whether the code being executed is in the parent or child process:
• If fork() returns 0, it means the code is executing in the child process.
• If fork() returns a positive value, it means the code is executing in the parent process,
and the return value is the PID (process ID) of the newly created child process.
• If fork() returns -1, it indicates an error occurred during the creation of the child
process.

iii. How many processes are being created?


In the provided code snippet, two processes are being created. This can be inferred from the
use of the fork() function. When fork() is called, it creates a new process by duplicating the
calling process. In this code, fork() is called once, so it creates one child process. Therefore,
there are two processes: the parent process and the child process.
b. Answer the following questions about processes and inter-process communication.
i. What is a context-switch?
A context-switch is the process of saving and restoring the state of a CPU such that multiple
processes can be executed concurrently on a single CPU core. When a multitasking operating
system schedules a new process to run, it performs a context-switch to save the current
process's state (registers, program counter, etc.) and load the state of the next process to be
executed. This allows the operating system to give the illusion of parallel execution to
multiple processes, even though only one process is actually executing at any given moment
on a single CPU core.
ii. Multiple processes can communicate with each other using shared-memory IPC
techniques. How does shared-memory IPC work?
Shared-memory IPC (Inter-Process Communication) allows multiple processes to
communicate by sharing a region of memory that is accessible to all of them. The basic steps
involved in shared-memory IPC are as follows:
1. Creation: A region of memory is allocated and marked as shared by multiple
processes.
2. Attachment: Each process that wants to communicate attaches (maps) the shared
memory region into its own address space.
3. Communication: Processes can read from and write to the shared memory region just
like any other memory.
4. Detachment: Once communication is complete, processes detach from the shared
memory region.
c. A shell provides an interface through which input from the user is gathered and
programs executed. The program output is then displayed
i. Which are the two major types of shells?
The two major types of shells are Bourne shell (sh) and C shell (csh). Additionally, there are
derivatives and alternatives such as Bash (Bourne Again Shell), Korn shell (ksh), and Z shell
(zsh).
ii. Write a simple Unix script that will display the date, calendar and print the name
"your is "What's your name"
#!/bin/bash

# Display current date


date

# Display calendar
cal

# Prompt for user's name


echo "What's your name?"
read name

# Print user's name


echo "Your name is $name"

iIi. Write down a script command or commands that will grant full privileges Unix in
ABC object an of users potential Unix
To grant full privileges (read, write, and execute) to all users for a file named "ABC" in Unix,
you can use the following command:
chmod ugo+rwx ABC
This command grants the owner (u), group (g), and others (o) full read, write, and execute
permissions on the file "ABC".
d. The Unix operating system is a set of programs that act as a link between the
computer and the user;
i. Outline any four distributions of Linux or Unix distributions.
Four distributions of Linux or Unix are:
1. Ubuntu
2. CentOS
3. Fedora
4. Debian
ii. Illustrate the basic block diagram of the Unix system, explaining the layers therein.
The basic block diagram of the Unix system typically consists of the following layers:
• Hardware Layer: This layer includes physical hardware components such as CPU,
memory, disks, etc.
• Kernel Layer: The kernel is the core of the Unix operating system. It interacts
directly with the hardware and provides essential services such as process
management, memory management, file system management, device drivers, etc.
• Shell Layer: The shell provides a command-line interface (CLI) through which users
interact with the operating system. It interprets user commands and executes them by
communicating with the kernel.
• User Programs Layer: This layer consists of various user-space programs and
utilities that run on top of the kernel. These programs perform specific tasks and
provide additional functionalities to users.
iii. In Unix, there are three basic types of files. Describe each of these types.
The three basic types of files in Unix are:
1. Regular Files: Regular files contain user data and can be text files, binary files, or
any other type of file. They are the most common type of files found in Unix systems.
2. Directories: Directories are special files that contain lists of other files and
directories. They provide a hierarchical structure for organizing and accessing files on
a Unix filesystem.
3. Special Files (or Device Files): Special files represent hardware devices or system
resources. They include character devices (such as terminals and serial ports) and
block devices (such as hard drives and SSDs). Special files allow user processes to
interact with hardware devices through device drivers provided by the kernel.

You might also like