0% found this document useful (0 votes)
12 views8 pages

Revision System Progamming

Uploaded by

nyaoroskitchen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Revision System Progamming

Uploaded by

nyaoroskitchen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

W1-2-60-1-6

JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY


UNIVERSITY EXAMINATIONS 2018/2019
THIRD YEAR SECOND SEMESTER SPECIAL/SUPPLEMENTARY
EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
ICS 2305: SYSTEMS PROGRAMMING
DATE: FEBRUARY 2019 TIME: 2 HOURS
----------------------------------------------------------------------------------------------------
INSTRUCTIONS:
ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS
===========================================================
QUESTION ONE [30 MARKS]
(a) Discuss briefly the services that operating systems provide to users and
programs. [10 marks]
Process Management: The OS manages processes, including process creation,
scheduling, termination, and communication between processes.

Memory Management: Allocating and deallocating memory as needed, managing


virtual memory, and protecting memory spaces of different processes.

File System Management: Providing an interface for file operations such as creation,
deletion, reading, and writing, as well as managing file permissions and directory
structures.
Device Management: Managing communication between peripheral devices and the
computer, including device drivers, input/output operations, and interrupt
handling.
Security: Enforcing access controls, authentication mechanisms, and ensuring data
integrity and confidentiality.

User Interface: Providing a user-friendly interface for interaction with the system, which
can be graphical, command-line-based, or a combination of both.

Networking: Managing network connections, protocols, and communication between


different nodes in a network.

Error Handling: Detecting and handling errors that occur during system operation to
prevent system crashes and data loss.

Resource Allocation: Managing system resources such as CPU time, memory, disk
space, and network bandwidth to optimize performance and ensure fairness among
users and applications.
(b) Describe the following terms as used in system programming. [10 marks]
(i) System call: A system call is a request made by a program to the operating
system kernel for performing tasks such as file manipulation, process
control, or communication. System calls provide an interface between user-
level processes and the kernel.

(ii) Process: A process is an instance of a program that is being executed. It


consists of the program code, execution state, memory space, and other
resources such as open files and network connections.

(iii) Thread: A thread is the smallest unit of execution within a process.


Threads share the same memory space and resources within a process and
can execute independently. Multithreading allows for concurrent execution
of tasks within a single process.

(iv) Device driver: A device driver is a software component that


facilitates communication between the operating system and hardware
devices such as printers, disk drives, or network adapters. It provides a
standardized interface for accessing device functionalities.

(v) File locking: File locking is a mechanism used to restrict access to a file or
a portion of a file to prevent concurrent access by multiple processes. It
ensures data consistency and prevents race conditions when multiple
processes attempt to read from or write to the same file simultaneously.
(c) Write down the shell code that will list all the sub directions of the current
directory on Unix. [4 marks]
ls -d */
(d) Outline three differences between memory management and using virtual
swapping. [6 marks]
Memory Management:
Involves managing physical memory (RAM) resources.
Allocates memory to processes, tracks memory usage, and deallocates memory
when processes terminate.
Ensures efficient utilization of available physical memory and prevents
memory fragmentation.
Virtual Swapping:
Involves using secondary storage (such as a hard disk) to supplement physical
memory when it becomes insufficient.
Pages of memory are swapped between RAM and disk to free up space for
active processes.
Helps in accommodating more processes than the physical memory can hold,
but swapping can lead to performance degradation due to disk I/O overhead.
QUESTION TWO [20 MARKS]
(a) Explain the role of controllers in 1/0 components of a computer system.
[6 marks]
Role of controllers in I/O components:
Controllers act as intermediaries between the CPU and peripheral devices,
managing the flow of data between them. They handle tasks such as data
transfer, error detection and correction, and protocol translation to ensure
efficient communication between the CPU and devices.

(b) Explain what an interrupt is. [3 marks]


An interrupt is a signal sent by a hardware device or software to the CPU to
request its attention. Interrupts can occur asynchronously, causing the CPU
to temporarily suspend its current execution and transfer control to an
interrupt handler. Interrupts allow for efficient multitasking and real-time
processing by enabling the CPU to respond promptly to external events and
device requests.
(c) Outline the two main purposes of IPC. [4 marks]
Inter-Process Communication (IPC):
Facilitates communication and data exchange between processes running
concurrently on a system.
Allows processes to synchronize their activities, share resources, and
coordinate their execution.
Enables collaboration between independent processes to accomplish
complex tasks efficiently.
(d) Briefly describe the following method of data exchange between two
processes.
Pipes:
Pipes provide a unidirectional communication channel between two
processes, with one process writing to the pipe and the other reading from it.
Typically used for communication between a parent process and its child
process or between chained processes in a pipeline.
Pipes have a limited capacity and are suitable for streaming data between
processes.
Shared Memory:
Shared memory allows multiple processes to access the same region of
memory concurrently.
Processes can read from and write to shared memory locations, enabling fast
and efficient data exchange.
Requires synchronization mechanisms such as semaphores or mutexes to
prevent data corruption and ensure consistency.
(e) Explain how Unix fork ( ) system call works. [3 marks]
The fork() system call in Unix creates a new process by duplicating the calling
process. After a successful fork(), two processes are created: the parent
process (the original process that called fork()) and the child process (the
newly created process). Both processes continue execution from the point of
the fork() call, but they have different process IDs (PIDs). The child process
inherits a copy of the parent process's memory, file descriptors, and other
resources. The fork() system call returns different values in the parent and
child processes: the PID of the child process to the parent and 0 to the child.
This mechanism allows for the creation of new processes for concurrent
execution or for executing a different program in the child process.
QUESTION THREE [20 MARKS]
(a) Describe the process involved when a process intends to communicate with
another process in remote machine using a socket. [6 marks]
Process communication via sockets:
Socket Creation: The sending process creates a socket using the socket() system
call, specifying the communication domain (e.g., AF_INET for IPv4), socket type
(e.g., SOCK_STREAM for TCP), and protocol (e.g., IPPROTO_TCP).
Connection Establishment: If the communication is connection-oriented (e.g.,
TCP), the sending process establishes a connection with the receiving process
using the connect() system call, providing the destination address and port
number.
Data Transfer: Once the connection is established, the sending process can use
system calls like send() or write() to transmit data to the receiving process over the
socket.
Data Reception: The receiving process uses the recv() or read() system call to
receive incoming data from the socket.
Connection Termination: After communication is complete, the sending or
receiving process can initiate the closure of the connection using the close()
system call.
(b) Differentiate between connection ……………….. and connectionless
communication. [4 marks]
Connection-Oriented Communication: In connection-oriented communication, a
reliable, bi-directional connection is established between the sender and receiver
before data transfer begins. Protocols like TCP ensure data integrity and order by
maintaining a virtual circuit between communicating parties.

Connectionless Communication: In connectionless communication, data is sent


without establishing a dedicated connection between sender and receiver. Each
packet is treated independently, and there is no guarantee of delivery or order.
Protocols like UDP (User Datagram Protocol
(c) What is the purpose of semaphores ? [2 marks]
Purpose of semaphores:
Semaphores are synchronization primitives used to control access to shared
resources in a concurrent system. They help coordinate the execution of multiple
processes or threads to prevent race conditions and ensure mutually exclusive
access to critical sections of code. Semaphores can be used to implement various
synchronization mechanisms such as mutexes, locks, and barriers.
(d) Briefly explain the file system used in Unix. [4 marks]
Unix file system:
The Unix file system organizes data on storage devices such as hard disks or SSDs
in a hierarchical structure consisting of directories and files. Each file is identified
by a unique name within its directory, and directories can contain other directories
(subdirectories) and files. Unix file systems support various file types, including
regular files, directories, symbolic links, device files, and named pipes.

(e) Discuss two ways that can be used to manage free disk storage for efficient
usage. [4 marks]
Disk Quotas: Disk quotas allow system administrators to set limits on the amount
of disk space that users or groups can consume. By enforcing disk quotas,
administrators can prevent individual users from monopolizing disk resources and
ensure fair allocation of storage space.

Disk Space Allocation Policies: File systems employ different allocation strategies
to manage free disk space efficiently. Techniques such as block suballocation,
delayed allocation, and extent-based allocation optimize disk space utilization by
reducing fragmentation and minimizing wasted space. Additionally, file systems
may employ techniques like compression and deduplication to further conserve
disk space.
QUESTION FOUR [20 MARKS]
(a) Briefly discuss the different types of processes in Unix. [4 marks]
Types of processes in Unix:
1. Foreground Processes: Foreground processes are interactive processes that
run in the foreground and interact directly with the user through the terminal.
They typically receive user input and provide output directly to the terminal.
2. Background Processes: Background processes are non-interactive
processes that run in the background without user intervention. They
continue executing even when the user is not actively interacting with the
terminal and do not require user input.
3. Daemon Processes: Daemon processes are system processes that run in the
background and perform various system-related tasks. They often run as
services, such as web servers, email servers, or print servers, and operate
without direct user interaction.

(b) Explain the different types of Unix commands that can be used in process
management. [6 marks]
Unix commands for process management:
1. ps: The ps command displays information about active processes, including their
process IDs (PIDs), CPU and memory usage, and execution status.
2. kill: The kill command sends signals to terminate or control processes. It allows
users to send specific signals, such as SIGKILL or SIGTERM, to terminate
processes gracefully or forcefully.
3. top: The top command provides real-time monitoring of system processes,
displaying a dynamic view of CPU and memory usage, process IDs, and other
relevant information.
4. nice: The nice command adjusts the priority of processes, allowing users to
change the scheduling priority of processes to allocate CPU resources more
effectively.
5. renice: The renice command allows users to change the priority of running
processes, adjusting their scheduling priority dynamically.

(c) Explain any 5 types of system calls used in file handling and management
in C programming. [10 marks]
System calls for file handling and management:
1. open(): Opens a file and returns a file descriptor for subsequent operations.
2. close(): Closes a file descriptor, releasing associated resources.
3. read(): Reads data from an open file into a buffer.
4. write(): Writes data from a buffer to an open file.
5. lseek(): Moves the file pointer associated with a file descriptor to a specified
position.
6. ioctl(): Performs I/O control operations on a file or device, such as setting flags or
querying device status.
QUESTION FIVE [20 MARKS]
(a) With the use of a diagram explain the windows system architecture.
[10 marks]
Windows system architecture:

The Windows system architecture consists of several layers:


1. User Mode: This layer contains user-space processes and applications, including
user interface components such as the Windows shell (explorer.exe) and user
applications like web browsers, word processors, and media players.
2. Kernel Mode: This layer includes the Windows kernel, which provides core
operating system services such as process and memory management, I/O
operations, and device driver support. The kernel interacts directly with hardware
components and manages system resources.
3. Hardware Abstraction Layer (HAL): The HAL abstracts hardware-specific
details and provides a standardized interface for accessing hardware devices. It
enables Windows to run on different hardware platforms with minimal
modification.
4. Device Drivers: Device drivers are software components that facilitate
communication between the operating system and hardware devices. They handle
tasks such as device initialization, data transfer, and interrupt handling.
5. Executive Services: Executive services are high-level system services provided
by the Windows executive, including process management, memory management,
I/O management, and security.
6. Win32 Subsystem: The Win32 subsystem provides compatibility with Win32-
based applications by translating Win32 API calls into native system calls. It
enables Windows to run a wide range of applications developed for the Win32
platform.
(b) Discuss two ways that can be used to manage free disk storage for efficient
usage. [4 marks]
Managing free disk storage:
1. Disk Quotas: Disk quotas allow system administrators to set limits on the amount
of disk space that users or groups can consume.
2. Disk Space Allocation Policies: File systems employ different allocation
strategies to manage free disk space efficiently, such as block suballocation,
delayed allocation, and extent-based allocation.

(c) Explain dynamic memory management and give examples of it in C


programming. [6 marks]
Dynamic memory management in C programming:
Dynamic memory management in C involves allocating and deallocating memory at
runtime using functions like malloc(), calloc(), realloc(), and free().
• malloc(): Allocates a block of memory of a specified size and returns a pointer to
the allocated memory.
• calloc(): Allocates a block of memory for an array of elements, initializes the
memory to zero, and returns a pointer to the allocated memory.
• realloc(): Resizes a previously allocated block of memory, potentially moving it
to a new location, and returns a pointer to the resized memory block.
• free(): Deallocates a block of memory previously allocated with malloc(),
calloc(), or realloc(), releasing the memory for reuse.
Dynamic memory management allows programs to adapt to changing memory
requirements at runtime and efficiently utilize available memory resources. It is
commonly used in scenarios where the size of data structures is unknown at
compile time or when managing large data sets. Examples of dynamic memory
usage in C programming include creating resizable arrays, implementing linked
data structures like linked lists and trees, and managing memory for strings and
buffers.

You might also like