0% found this document useful (0 votes)
68 views

Revision System Progamming 2

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)
68 views

Revision System Progamming 2

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/ 10

W1-2-60-1-6

JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY


UNIVERSITY EXAMINATIONS 2021/2022
YEAR 3 SEMESTER 2 EXAMINATION FOR THE DEGREE FOR BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
ICS 2305: SYSTEMS PROGRAMMING

DATE: AUGUST 2022 TIME: 2 HOURS

INSTRUCTIONS: Answer question One (Compulsory) Any Other Two Questions

QUESTION ONE [30 MARKS]

a. Define the term system software and its contribution to systems programming [2 marks]
System software refers to a set of programs that manage the resources and provide a
platform for running application software
Its main contribution to systems programming lies in providing an interface between
hardware and software, managing memory, handling input/output operations, and providing
essential services like file management and security. System software includes operating
systems, device drivers, utility programs, and compilers

b. Explain the importance of the following system tools to a programmer [4 marks]


i) System Libraries: System libraries provide pre-written code modules that programmers
can use to perform common tasks without having to rewrite code from scratch. They
offer functions and procedures for tasks like input/output operations, string
manipulation, mathematical calculations, and more. By using system libraries,
programmers can save time, ensure code reliability, and promote code reuse.
ii) Debugger: A debugger is a crucial tool for programmers to identify and fix errors in
their code. It allows programmers to execute code step-by-step, inspect variables, set
breakpoints, and analyze program behavior during runtime. With a debugger,
programmers can detect logical errors, trace program flow, and optimize code for better
performance and reliability.
c. Describe how source code saved as a welcome.c would be completed and executed via shell
[4 marks]
#include <stdio.h>
int main() {
printf("Welcome to the world of programming!\n");
return 0;
}
d. Briefly describe below classification of device drivers [4 marks]
i) Network Device Driver: Manages communication between the operating system and
network hardware. It facilitates data transmission over a network and handles tasks such as
packet routing, error detection, and network protocol implementation.
ii) Pseudo Device Driver: Simulates hardware devices or provides access to system
resources through a device interface. Pseudo device drivers are often used for inter-process
communication, virtual file systems, or accessing kernel data structures.
e. Differentiate between named and unnamed pipes [2 marks]
Named Pipes: Also known as FIFOs (First-In-First-Out), named pipes are named file objects
that allow communication between unrelated processes. They exist as special files in the file
system and are created using the mkfifo command. Named pipes can be used for
communication between processes even if they are not related or share a common parent.

Unnamed Pipes: Unnamed pipes, also called anonymous pipes, are created using the pipe
system call and are typically used for communication between parent and child processes or
between processes within the same process chain. Unnamed pipes are created implicitly
when the parent process forks, and they provide unidirectional communication between the
processes.
f. Describe the two system calls for changing a files permission [4 marks]
chmod: The chmod system call changes the permissions of a file or directory. It takes a
numeric mode or symbolic mode as an argument to specify the new permissions.
fchmod: The fchmod system call is similar to chmod, but it operates on a file descriptor
rather than a filename. It changes the permissions of the file associated with the specified file
descriptor.
g. List any three improvements in IA-32 architecture [3 marks]
Improvements in IA-32 Architecture:
Three improvements in IA-32 (x86) architecture:
i) Increased Address Space: IA-32 architecture has evolved to support larger address
spaces, allowing systems to address more memory. This enhancement enables support
for more extensive applications and data sets.
ii) Enhanced Instruction Set: Over time, IA-32 processors have introduced new
instructions and extensions to improve performance and support advanced computing
tasks like multimedia processing, cryptography, and virtualization.
iii) Improved Power Efficiency: Modern IA-32 processors incorporate power-saving
features and advanced microarchitecture techniques to improve energy efficiency and
reduce power consumption without compromising performance
h. Define virtualization and give examples of virtual systems [3 marks]
Virtualization is the process of creating a virtual (rather than actual) version of something, such
as a hardware platform, operating system, storage device, or network resources. It enables the
simultaneous execution of multiple operating systems or applications on a single physical
machine, allowing efficient resource utilization and isolation between virtual environments.
Examples of virtual systems include:
1. Virtual Machines (VMs): Software-based emulation of computer systems, where each
VM runs its own guest operating system on a host machine. Popular VM platforms
include VMware, VirtualBox, and Microsoft Hyper-V.
2. Containerization: Lightweight virtualization method that allows applications to run in
isolated environments called containers. Containers share the host operating system's
kernel and resources, providing fast startup times and efficient resource utilization.
Examples include Docker and Kubernetes.
3. Virtual Desktop Infrastructure (VDI): Centralized desktop virtualization technology
that hosts desktop environments on remote servers and delivers them to users over a
network. Users access virtual desktops using thin client devices, enabling flexible and
secure remote access to computing resources.

i. With a good examples show how a pointer is declared in c [2 marks]


int *ptr; // Declares a pointer to an integer
j. Using examples outline any two types of editors in Linux [2 marks]
Types of Editors in Linux:
Two types of editors commonly used in Linux:
1. Command-Line Text Editors: These editors run in a terminal environment and are
operated entirely through text commands. Examples include Vim (Vi Improved), Emacs,
and Nano. They offer powerful editing capabilities but may have a steep learning curve
for beginners.
2. Graphical Text Editors: Graphical editors provide a user-friendly interface with menus,
toolbars, and mouse support for editing text files. Examples include Gedit, Kate, and
Sublime Text. They are easier to use for beginners and offer features like syntax
highlighting, code folding, and plugin support.
QUESTION TWO [20 MARKS]

a. Write a system call to create a file myfile.doc and write into it “This is my file” [6 marks]
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int fd;
char *text = "This is my file\n";
// Create the file
fd = open("myfile.doc", O_CREAT | O_WRONLY, 0644);
// Write to the file
write(fd, text, strlen(text));
// Close the file
close(fd);
return 0;
}
b. Describe the following;
i) The c standard library
The C Standard Library is a collection of predefined functions and macros that
provide essential utilities for C programming.
The C Standard Library is specified by the ISO C standard and is available on most C
compilers
ii) The x library [4 marks]
The X Library (libX11) is a library used for programming graphical user interfaces (GUIs) on Unix
and Unix-like systems.
c. Write a shell script to display free space, time, partition disk, file system [6 marks]
#!/bin/bash
# Display free space
df -h
# Display current time
date
# Display partition information
fdisk -l
# Display file system information
Lsblk
df -h: Displays disk space usage in a human-readable format.

date: Prints the current date and time.

fdisk -l: Lists partition information of all disks.

lsblk: Lists information about block devices (including partitions and mount
points).

d. List four features of Unix like operating system [4 marks]


Multiuser Support: Unix-like operating systems allow multiple users to access the system
simultaneously, each with their own user account and privileges. User authentication and access
control mechanisms ensure security and privacy.

Multitasking: Unix-like systems support multitasking, allowing multiple processes to run


concurrently. The operating system efficiently schedules and manages processes, ensuring
optimal resource utilization.

File System Hierarchy: Unix-like systems follow a hierarchical file system structure, organizing
files and directories in a tree-like manner. This structure facilitates organization, navigation, and
management of files and directories.

Networking Capabilities: Unix-like operating systems provide robust networking capabilities,


allowing systems to communicate with each other over local networks or the internet. They
support networking protocols such as TCP/IP and provide tools for network configuration,
communication, and administration.
QUESTION THREE [20 MARKS]

a. Define the term socket [2 marks]


A socket is a communication endpoint that allows processes to communicate with each
other, either on the same machine or across a network. In networking, a socket represents a
connection point between a client and a server. It provides an interface for processes to send
and receive data.
b. Discuss the steps of creating a socket between a server and a client in a connection-oriented
paradigm [5 marks]
Server Initialization:
Create a socket using the socket() system call, specifying the address family (e.g., AF_INET
for IPv4) and socket type (e.g., SOCK_STREAM for TCP).
Bind the socket to a specific IP address and port using the bind() system call.
Listen for incoming connections using the listen() system call.
Client Initialization:
Create a socket using the socket() system call, specifying the same address family and socket
type as the server.
Connect to the server using the connect() system call, providing the server's IP address and
port number.
Communication:
Once the connection is established, both the server and client can send and receive data using
the socket.
The server uses the accept() system call to accept incoming connections and create a new
socket for communication with the client.
The client and server exchange data using the send() and recv() system calls for connection-
oriented communication.
c. Describe three basic files in Unix [3 marks]
Regular Files: Regular files contain user data and can be text files, binary files, or any other
type of file. They are identified by the absence of any special attributes or characteristics.
Directories: Directories are special files that store the names and metadata of other files and
directories. They provide a hierarchical structure for organizing files on a Unix-like file
system.
Device Files: Device files represent hardware devices or pseudo-devices in the Unix file
system. They allow user processes to interact with hardware components such as disks,
terminals, printers, and network interfaces. Device files are categorized into block devices
(e.g., hard drives) and character devices (e.g., keyboards).
d. Explain the following lines of code: [4 marks]
Int fd;
Fd=open (˝/home/Kidd/Madagascar˝¸O_RDONLY);
int fd;: Declares an integer variable named fd, which will hold the file descriptor returned
by the open() system call.
fd = open("/home/Kidd/Madagascar", O_RDONLY);: Opens the file named
"Madagascar" located in the directory "/home/Kidd/" for reading only (O_RDONLY
flag). The open() system call returns a file descriptor (fd) that represents the opened file.

e. Write the commands to do the following: [6 marks]


i) Move a file
mv source_file destination_directory
ii) Count content
wc -l filename
iii) Renaming a file
mv old_filename new_filename
iv) Make directory
mv old_filename new_filename
v) Remove directory
rmdir directory_name
QUESTION FOUR [20 MARKS]

a. Create a program that uses a linked list to store employees the details. Request user to enter
details of two employees and then print [6 marks]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Structure to represent an employee
struct Employee {
char name[50];
int age;
float salary;
struct Employee *next;
};
int main() {
struct Employee *head = NULL;
struct Employee *temp, *newNode;
char choice;
// Request user to enter details of two employees
for (int i = 0; i < 2; i++) {
newNode = (struct Employee *)malloc(sizeof(struct
Employee));
if (newNode == NULL) {
printf("Memory allocation failed!\n");
exit(1);
}
printf("Enter details of employee %d:\n", i + 1);
printf("Name: ");
scanf("%s", newNode->name);
printf("Age: ");
scanf("%d", &newNode->age);
printf("Salary: ");
scanf("%f", &newNode->salary);
newNode->next = NULL;
if (head == NULL) {
head = newNode;
temp = newNode;
} else {
temp->next = newNode;
temp = newNode;
}
}
// Print the details of employees stored in linked list
temp = head;
printf("\nDetails of employees:\n");
while (temp != NULL) {
printf("Name: %s, Age: %d, Salary: %.2f\n", temp->name,
temp->age, temp->salary);
temp = temp->next;
}
// Free allocated memory
while (head != NULL) {
temp = head;
head = head->next;
free(temp);
}
return 0;
}
b. List two examples of system software and two examples of application software [4 marks]
System Software:
Operating Systems (e.g., Windows, Linux, macOS)
Device Drivers (e.g., printer drivers, graphics drivers)
Application Software:
Web Browsers (e.g., Google Chrome, Mozilla Firefox)
Word Processors (e.g., Microsoft Word, LibreOffice Writer)
c. Explain the term kennel in system programming and briefly state the functions [4 marks]
In system programming, the term "kernel" refers to the core component of an operating
system. It acts as a bridge between hardware and software, managing system resources and
providing essential services. The functions of the kernel include:
Process Management: The kernel creates, schedules, and terminates processes. It allocates
CPU time to processes and ensures fair execution.
Memory Management: It manages system memory, allocating memory to processes and
managing virtual memory. The kernel also handles memory protection to prevent
unauthorized access.
File System Management: The kernel provides an interface for file operations, such as
reading, writing, and organizing data on storage devices. It manages file access permissions
and directory structures.
Device Management: The kernel controls communication with hardware devices, managing
device drivers and providing an abstraction layer for interacting with devices. It handles
device initialization, input/output operations, and device interrupts.
d. Write a simple bash script to perform a back up task form a directory of choice [6 marks]
#!/bin/bash
# Source directory to be backed up
source_dir="/path/to/source_directory"

# Destination directory for backup


backup_dir="/path/to/backup_directory"

# Backup filename with timestamp


backup_file="backup_$(date +'%Y%m%d').tar.gz"

# Create backup using tar command


tar -czf "$backup_dir/$backup_file" "$source_dir"

# Check if backup was successful


if [ $? -eq 0 ]; then
echo "Backup completed successfully."
else
echo "Backup failed."
fi

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy