Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views9 pages

OS Lab Manual 02

The document is a lab manual for Linux commands and system calls, detailing various commands such as date, calendar, who, and system calls like read and write. It provides syntax, usage, and examples for each command, along with an explanation of system calls and their categories. Additionally, it includes instructions for using the nano text editor and practice tasks for implementing the write system call in C language.

Uploaded by

benthemalik
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)
15 views9 pages

OS Lab Manual 02

The document is a lab manual for Linux commands and system calls, detailing various commands such as date, calendar, who, and system calls like read and write. It provides syntax, usage, and examples for each command, along with an explanation of system calls and their categories. Additionally, it includes instructions for using the nano text editor and practice tasks for implementing the write system call in C language.

Uploaded by

benthemalik
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/ 9

SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION UNIVERSITY

OPERATING SYSTEM LAB MANUAL


Linux Commands and System Calls (read, write)

1. Date Command: This command is used to display the current data and time.
Syntax:
date
date +%ch
Here are some options that can be used with date +%____
a = Abbreviated weekday. A = Full weekday. b = Abbreviated month.
B = Full month. c = Current day and time. C = Display the century as a
decimal number.
d = Day of the month. D = Day in „mm/dd/yy‟ h = Abbrevated month day.
format
H = Display the hour. L = Day of the year. m = Month of the year.
M = Minute. P = Display AM or PM S = Seconds
T = HH:MM:SS format u = Week of the year. y = Display the year in 2 digit.
Y = Display the full year. Z = Time zone

2. Calendar Command: This command is used to display the calendar of the year or the
particular month of calendar year.
Syntax :
a. cal <year> cal 1993
b. cal <month> <year> cal Jun 1993 , cal June 1993 , cal 06 1993
Here the first syntax gives the entire calendar for given year & the second Syntax gives the
calendar of reserved month of that year.

3. To see the current amount of free space on your disk drives, enter df

4. Likewise, to display the amount of free memory, enter the free command.
5. We can end a terminal session by either closing the terminal emulator window, or by
entering the exit command at the shell prompt.

6. who Command: It is used to display who are the users connected to our computer currently.
Syntax:
who – option
Options :
H–Display the output with headers
b–Display the last booting date or time or when the system was lastly rebooted

7. who am i Command: Display the details of the current working directory.


Syntax:
whoami

8. CLEAR Command: It is used to clear the screen.


Syntax:
clear
9. MAN Command: It help us to know about the particular command and its options & working.
It
is like help command in Windows OS.
Syntax:
man <command name>
man 2 write

System calls are fundamental interfaces between userlevel applications and the operating
system kernel. These calls allow applications to request services from the operating system,
such as performing I/O operations, managing processes, accessing files, and more. System calls
provide an abstraction layer, enabling applications to interact with the underlying hardware and
resources in a controlled and secure manner.
Here are some common categories of system calls:
1. Process Control:
fork(): Create a new process by duplicating the current process.
exec(): Replace the current process's memory image with a new one.
exit(): Terminate the current process.

2. File Management:
open(): Open a file or create a new one.
read(): Read data from a file.
write(): Write data to a file.
close(): Close a file.

3. Device Management:
ioctl(): Perform I/O control operations on devices.
read() and write() with device files: Interact with devices using filelike interfaces.

4. Information Maintenance:
getpid(): Return the process ID of the calling process.
getppid(): Return the parent process ID of the calling process.
times(): Return information about process resource utilization.

5. Memory Management:
brk(): Set the end of the data (heap) segment.
mmap(): Map files or devices into memory.

6. Communication:
pipe(): Create an interprocess communication channel.
socket(): Create a communication endpoint for network communication.
send() and recv(): Send and receive messages over a network socket.
7. File System Manipulation:
chdir(): Change the current working directory.
mkdir() and rmdir(): Create and remove directories.
link() and unlink(): Create and remove hard links.

8. Security:
chmod(): Change file permissions.
chown(): Change file ownership.

These system calls, along with others, form the foundation for interactions between userlevel
applications and the operating system. The exact set of system calls and their implementations
can vary between different operating systems. The C programming language often provides a
standard library that encapsulates these system calls, making it easier for developers to work
with them in a portable way.

To make “Write” System call follow the steps below:


Step 1: Open Ubuntu and Type: man 2 write

After Pressing Enter you will get Linux Programmer's Manual


If you are unable to get the Linux Programmer Manual:
Try the following commands and then repeat Step 1
1. sudo apt-get update
2. sudo apt-get install gcc

The sudo apt-get update command is used on Debianbased Linux systems, such as Ubuntu, to
update the local package repository information. Let's break down the command:
sudo: Stands for "Superuser Do." Allows a permitted user to execute a command as the
superuser or another user.
aptget: A commandline package management tool used on Debianbased systems. Helps in
handling packages—installing, updating, upgrading, and removing them.
update: A specific subcommand for apt-get. Used to download package information from all
configured sources listed in /etc/apt/sources.list or the files in the /etc/apt/sources.list.d/
directory.
The command sudo apt-get install gcc is used on Debianbased Linux systems, such as Ubuntu,
to install the GNU Compiler Collection (GCC). Let's break down the command:
install: A specific subcommand for apt-get. Used to install new packages on the system.
gcc: The package name of the GNU Compiler Collection. GCC includes compilers for various
programming languages, such as C, C++, Fortran, Ada, and others.

The nano command is a text editor available in Linux. It provides a simple and user-friendly
interface for text editing within the terminal.
Here's how you can use the nano command:

nano [filename] // like nano w.c to create a “c” program file named “w”
filename: Optional. You can specify the name of the file you want to edit. If the file does not
exist, nano will create a new file with that name.

Key Bindings in nano:

Save and Exit:


Press Ctrl + O to write the changes (save).
Press Enter to confirm the file name.
Press Ctrl + X to exit.

Exit Without Saving:


If you don't want to save changes, press Ctrl + X without pressing Ctrl + O before.

Navigation:
Use arrow keys for navigation.

Cut, Copy, Paste:


Ctrl + K: Cut (delete) the current line.
Ctrl + U: Paste the cut text.
Search:
Ctrl + W: Search for a pattern.
Ctrl + Shift + _: Search backward.

Other Operations:
Ctrl + G: Display help.
Ctrl + C: Display current line and file status.
Ctrl + J: Justify (format) the current paragraph.

Line Numbers:
Ctrl + _: Go to a specific line number.

Inserting and Deleting:


Ctrl + T: Insert a new file.
Ctrl + D: Delete the current character.
Alt + U: Undo the last action.
Alt + E: Redo the last undone action.

These are just some of the basic key bindings in nano. You can find additional commands and
options in the help screen (Ctrl + G). Overall, nano is designed to be user-friendly and is a great
choice for quick and simple text editing in the terminal.

Read and Write System Calls


In Linux, the read and write system calls are used for input and output operations, respectively,
at a low level. These system calls are essential for performing file I/O, working with standard
input/output, and interacting with devices.

Write System Call in C Language


#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
• Parameters:
• fd: File descriptor representing the file or output destination.
• buf: Buffer containing the data to be written.
• count: Number of bytes to write.

Example:

#include<unistd.h>
#include<stdio.h>
int main ()
{
write(1,"Hello",5); // generate output of 5 characters
}

Read System Call in C Language


#include <unistd.h>
ssize_t read(int fd, void *buf, size_t count);
• Parameters:
• fd: File descriptor representing the file or input source.
• buf: Buffer where the read data will be stored.
• count: Number of bytes to read.

Example:

#include<unistd.h>
#include<stdio.h>
int main ()
{
char inp[5]; //container to store a value
printf("Reading a line from User "); //printing line to on console
read(0,inp,5); //reading with System Call

write(1,inp,5); //writing the input with System Call


}

Practice Tasks:

1. Create a file named write1.c


2. Take Name as an input with read system call
3. Show the output with write system call

You might also like