OS Manual
OS Manual
Aim: Study the features of all the major operating systems evolved and
perform comparative analysis.
Man: man command in Linux is used to display the user manual of any command that we can
run on the terminal.
Description:
Option Use
Example:
Echo: It's used for displaying lines of text or string which are passed as arguments on the
command line.
Description:
Option Use
Example:
Printf: It's used to display the given string, number or any other format specifier on the
terminal window.
Description:
Option Use
Example:
Cal: cal command displays a calendar of the specified year or month. The Year parameter
names the year for which you want a calendar.Syntax: cal [ [ month ] year]
Description:
Option Use
cal -y Shows the calendar of the complete current year with the
current date highlighted.
Example:
Date: date command is used to display the system date and time. date command is also used
to set date and time of the system.
Description:
Option Use
–file or -f This is used to display the date string present at each line of file
in the date and time format.
-s or –set To set the system date and time -s or –set option is used.
Example:
Description:
Option Use
Example:
Who am i: whoami command is used both in Unix Operating System and as well as in
Windows Operating System.
● It is basically the concatenation of the strings “who”,”am”,”i” as whoami.
● It displays the username of the current user when this command is invoked.
● It is similar as running the id command with the options -un.
Syntax: $whoami
Description:
Option Use
Example:
Syntax: $ history
Description:
Option Use
Example:
Cd: cd command in linux known as change directory command. It is used to change current
working directory.
Syntax: $ cd [directory]
Description:
Option Use
Example:
Pwd: pwd stands for Print Working Directory. It prints the path of the working directory,
starting from the root.
Syntax: $ pwd
Option Use
Example:
Mkdir: mkdir command in Linux allows the user to create directories. This command can
create multiple directories at once as well as set the permissions for the directories.
Description:
Option Use
Example:
Description:
Option Use
–help It will print the general syntax of the command along with the
various options that can be used with the rmdir command as well
as give a brief description about each option.
–version This option is used to display the version information and exit.
Example:
Syntax: $ ls [Option]…[
Description:
Option Use
-A To show the hidden files, but not the ‘.’ (current directory) and
‘..’ (parent directory).
Example:
Example:
Cp: cp stands for copy. This command is used to copy files or group of files or directory. It
creates an exact image of a file on a disk with different file name. cp command require at
least two filenames in its arguments.
Syntax:
cp [OPTION] Source Destination
Description:
Option Use
-i With this option system first warns the user before overwriting
the destination file.
With this option cp command creates the backup of the
-b destination file in the same folder with the different name and in
different format.
If the system is unable to open destination file for writing
-f operation because the user doesn’t have writing permission for
this file then by using -f option with cp command, destination file
is deleted first and then copying of content is done from source to
destination file.
Example:
Description:
Option Use
The -i option makes the command ask the user for confirmation
-i before removing each file, you have to press y for confirm
deletion, any other key leaves the file un-deleted.
The -f option overrides this minor protection and removes the file
-f forcefully.
With -r(or -R) option rm command performs a tree-walk and will
-r delete all the files and sub-directories recursively of the parent
directory.
Example:
Description:
Option Use
The -i option makes the command ask the user for confirmation
-i before moving a file that would overwrite an existing file, you
have to press y for confirm moving, any other key leaves the file
as it is.
The -f option overrides this minor protection and overwrites the
-f destination file forcefully and deletes the source file.
With -n option, mv prevent an existing file from being
-n overwritten.
Example:
Aim: Execute memory management commands: free, df, top, ps and kill.
Free: This command shows the free and used memory (RAM) on the Linux system.
Option Use
-b It displays the memory in bytes.
-k It displays the amount of memory in kilobytes(default).
-m It displays the amount of memory in megabytes.
Example:
Df: This utility reports the free disk space(Hard Disk) on all the file systems
Option Use
-a If you want to display all the file system.
-h Display size in power of 1024.
-H Display sizes in power of 1000.
Example:
Description:
Option Use
-s Use top in Secure mode.
-b Send output from top to file or any other programs.
-c The command starts top with last closed state.
Example:
Ps: To check all the processes running under a user, use the command.
Syntax: ps [options]
Description:
Option Use
-T View all processes associated with this terminal.
-r View all the running processes.
-x View all processes owned by you.
Example:
Syntax: $kill -l
Description:
Option Use
Example:
Aim: Write a program using the following system calls of UNIX operating system: fork,
exec, getpid, exit, wait.
Code:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
void main()
{
int p;
int status;
p=fork();
printf("PID BEFORE fork: %u\n",getpid());
if(p==0)
{
printf("For Child process: \n");
printf("PID of child process: %u\n",getpid());
printf("PPID of child process: %u\n",getppid());
execl("/bin/ls","ls","-l",(char*)0);
_exit(1);
}
else
{
printf("For Parent process: \n");
printf("PID of parent process: %u\n",getpid());
printf("PPID of parent process: %u\n",getppid());
wait(&status);
}
if(p==-1)
{
printf("Can't fork");
_exit(1);
}
}
Output: