UNIX Chapter 1
UNIX Chapter 1
UNIX Chapter 1
The Unix operating system is a set of programs that act as a link between the computer and the
user. Unix is written using a C programming language.
The computer programs that allocate the system resources and coordinate all the details of the
computer's internals is called the operating system or the kernel.
o It is the computer program that first loaded on start-up the system (After the bootloader). Once
it is loaded, it manages the remaining start-ups. It also manages memory, peripheral, and I/O
requests from software. Moreover, it translates all I/O requests into data processing
instructions for the CPU. It manages other tasks also such as memory management, task
management, and disk management.
➢ Functions of a Kernel
▪ Device Management:
A kernel manages the various peripheral devices connected to the computer and
controls them using device drivers.
▪ Memory Management:
A kernel controls the computer's memory and allocates it to processes safely. It
uses virtual addressing to prevent processes from crashing into each other.
▪ Resource Management:
A kernel shares resources between processes, ensuring that each process
uniformly accesses the resource. It also provides synchronization and inter-
process communication.
1. Monolithic Kernel - In a monolithic kernel, all the operating system services run in kernel space,
which provides efficient communication between components. Example: Unix, Linux, Open VMS,
XTS-400 etc.
2. Micro Kernel – A microkernel only includes the essential services in kernel space, and other
services run in user space. This approach reduces the kernel's size and improves the system's
reliability. Example: Mach, L4, AmigaOS, Minix, K42 etc.
3. Hybrid Kernel – It is the combination of both monolithic kernel and microkernel. It has speed
and design of monolithic kernel and modularity and stability of microkernel. Example: Windows NT,
Netware, BeOS etc.
4. Exo Kernel - An exokernel is an operating system architecture that exposes the hardware
resources directly to user-level applications, Example: Nemesis, ExOS etc.
5. Nano Kernel – It is the type of kernel that offers hardware abstraction but without system
services. Micro Kernel also does not have system services therefore the Micro Kernel and Nano
Kernel have become analogous. Example: EROS etc.
Layer-3: The Shell– SHELL is a program which provides the interface between the user and an
operating system. When the user logs in OS starts a shell for user.
• The interface between the user and kernel. It is a program
that interprets/translates commands typed into the terminal into a series of commands that
can be sent to the shell. This script containing commands is called a shell script.
• There are various commands like cat, mv, cat, grep, id, wc, and many more.
o C Shell: The C shell is another popular shell commonly available on a UNIX system. Bill Joy
created it at the University of California at Berkeley. It incorporated features such as aliases
and command history. It includes helpful programming features like built -in arithmetic and
C-like expression syntax.
o Korn Shell: It was written by David Korn at AT&T Bell Labs. It is a superset of the Bourne
shell. So it supports everything in the Bourne shell. It has interactive features. It includes
features like built-in arithmetic and C-like arrays, functions, and string-manipulation
facilities. It is faster than C shell.
Layer-4: Application Programs Layer - It is the outermost layer that executes the given external
applications.
➢ It executes external applications like word processors and graphic programs.
➢ UNIX distributions typically come with several useful applications programs as standard. For
Example: emacs editor, StarOffice, xv image viewer, g++ compiler etc.
➢ Difference between Shell and Kernel :
S.No. Shell Kernel
1. Shell allows the users to communicate with the kernel. Kernel controls all the tasks of the system.
2. It is the interface between kernel and user. It is the core of the operating system.
• Open Source: Being open-source, the UNIX operating system is freely available to the
community for use and customization.
• Multitasking: The UNIX operating system allows you to launch several tasks or processes
from the same terminal, with one running in the foreground and the other in the background.
• Multi-user: Multiple users can access compute resources in a UNIX operating system.
Different terminals can be used to log in by the user. Time-sharing mechanisms are used
where a scheduler allots time to different jobs based on a scheduling technique.
• Utilities: Various types of tools are available on the UNIX operating system. These
include grep, sed, awk, etc. These tools can be used in compilers, network applications, and
remote services.
• Portability: Because a large percentage of the UNIX operating system is written in
the C language and only a tiny portion is coded for specific hardware, it ensures the transfer of
code to any computer system. This makes the UNIX operating system highly portable.
• File Security and Protection: UNIX is a multi-user which makes it more vulnerable to
security threats. Thus, UNIX places importance on file security and protection. UNIX security
measures include giving usernames and passwords, providing authentication, allowing file
access permissions, and file encryption .
• Command Structure: UNIX commands are straightforward to learn and use. Commands in
UNIX are case-sensitive (i.e. UNIX treats lowercase and uppercase characters separately) and
they are mostly written in lowercase. Example: cp, mv etc.
• Communication: UNIX operating system supports communication methods using
the write command, mail command, etc.
• Accounting: UNIX maintains track of the jobs that the user creates. This function improves
system performance by monitoring CPU use and verifying disk space. These accounting duties
may be performed by the root user using different commands such as quota, df, du, and so on.
1. Parent and Child Process: A child process is a Linux process that is created by another process
known as the parent process. A child process can be created using one of two methods. The first
method is the fork system call, which is often used in Unix-like operating systems, whereas the
second method is the spawn method, which is preferred in the modern NT kernel of Microsoft
Windows. A process is considered a parent process if it creates one or more child (subprocess)
processes.
2. Zombie and Orphan process: A zombie process is a Linux process that has finished its execution
but still has an entry in the process table. Zombie processes usually get created when a child process
completes its execution but the parent process has yet to read its exit status.
An orphan process is a process that continues to run even after the parent process has been
completed or terminated. An orphan process can be intentionally or unintentionally created.
The process runs in the foreground, the output is directed to my screen, and if the ls command wants
any input (which it does not), it waits for it from the keyboard.
• Background Processes: They run in the background and usually do not need user input. For
example, Antivirus.
To start a background Linux process, add an ampersand (&) to the end of the command.
• In unix, We can use the ps command to display the list of the running processes.
$ ps
PID TTY TIME CMD
19 pts/1 00:00:00 sh
24 pts/1 00:00:00 ps
• The -f (f for full) option is one of the most commonly used options for the ps command, and it
offers extra information, as shown in the following example.
$ ps –f
UID PID PPID C STIME TTY TIME CMD
52471 19 1 0 07:20 pts/1 00:00:00f sh
52471 25 19 0 08:04 pts/1 00:00:00 ps -f
For a running program (named process) Pidof finds the process id’s (pids)
Fields described by ps are described as:
• UID: User ID that this process belongs to (the person running it)
• PID: Process ID
• PPID: Parent process ID (the ID of the process that started it)
• C: CPU utilization of process
• STIME: Process start time
• TTY: Terminal type associated with the process
• TIME: CPU time is taken by the process
• CMD: The command that started this process
There are other options which can be used along with ps command :
• -a: Shows information about all users
• -x: Shows information about processes without terminals
• -u: Shows additional information like -f option
• -e: Displays extended information
➢ Stopping a process:
When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For
processes running in background kill command can be used if it’s pid is known.
$ ps –f
UID PID PPID C STIME TTY TIME CMD
52471 19 1 0 07:20 pts/1 00:00:00 sh
52471 25 19 0 08:04 pts/1 00:00:00 ps –f
$ kill 19
Terminated
• If a process ignores a regular kill command, you can use kill -9 followed by the process ID.
$ kill -9 19
Terminated
Other process commands:
o bg: A job control command that resumes suspended jobs while keeping them running in the
background.
Syntax: bg [ job ]
For example: bg %19
o top: This command is used to show all the running processes within the working
environment of Linux.
Syntax: top
o nice: It starts a new process (job) and assigns it a priority (nice) value at the same
time. Syntax: nice [-nice value]
nice value ranges from -20 to 19, where -20 is of the highest priority.
o renice : To change the priority of an already running process renice is used. Syntax: renice [-
nice value] [process id]
o df: It shows the amount of available disk space being used by file systems. Syntax: df
Output:
none 4 0 4 0% /sys/fs/cgroup
o free: It shows the total amount of free and used physical and swap memory in the
system, as well as the buffers used by the kernel. Syntax: free
Output:
total used free shared buffers cached
Mem: 1006708 935872 70836 0 148244 346656
-/+ buffers/cache: 440972 565736
Swap: 262140 130084 132056
FILES in UNIX:
• A file system is a logical collection of files on a partition or disk.
• A file is the smallest unit in which the information is stored.
2. Directory: Directory store both special as well as ordinary files. A directory file includes an entry
file for each file and a subdirectory which it houses. If there are 5 files in a directory, then there will
be 5 entries in the directory. Every entry comprises of 2 components.
1. The name of the File.
2. An inode number, which is a unique identification number for the file or directory.
In the long-format output of ls -l, we used the "d" symbol in order to specify this kind of file.
3. Special Files: We use special files to represent the real physical device like terminal, tape drive,
and printer. and also used for Input/Output(I/O) operations. Special files or devices are used for
Input/Output(I/O) on Linux and Unix systems. They look as similar to the ordinary file or directory in a
file system.
o In the long-format output of ls -l, using the "c" symbol character distinct, files are marked.
o In the long-format output of ls -l, using the "b" symbol block, distinct files are marked.
4. Pipes: Pipes is like a temporary file that only exists to hold the data from one command till it is
read by another. A one-way flow of data is provided by the Unix pipe. In order to create a pipe, the
vertical bar (|) has to be placed on the command line between 2 commands. Such as who | wc -l.
In the long-format output of ls -l, known as pipes, are marked using the symbol "p."
5. Sockets: Unix sockets are a type of file that enables for advanced inter-process communication.
It is also known as inter-process communication socket. In the framework of the client-server
application, a Unix Socket is used.
In the long-format output of ls -l, using the "s" symbol, Unix sockets are marked.
6. Symbolic Link: The symbolic link is used to reference another file in the file system. In order to
reference another file of the file system, we use the symbolic link. The symbolic file will not function
if the source file is deleted or moved to the different location.
In the case of the long-format output of ls -l, using the "l" symbol, the symbolic link is marked.
Sr.No. Directory & Description
/
1 This is the root directory which should contain only the directories needed at the top
level of the file structure
2 /bin
This is where the executable files are located. These files are available to all users
3 /dev
These are device drivers
/etc
4 Supervisor directory commands, configuration files, disk configuration files, valid user
lists, groups, ethernet, hosts, where to send critical messages
5 /lib
Contains shared library files and sometimes other kernel-related files
6 /boot
Contains files for booting the system
7 /home
Contains the home directory for users and other accounts
/mnt
8 Used to mount other temporary file systems, such as cdrom and floppy for the CD-
ROM drive and floppy diskette drive, respectively
/proc
9 Contains all processes marked as a file by process number or other information that is
dynamic to the system
10 /tmp
Holds temporary files used between system boots
/usr
11 Used for miscellaneous purposes, and can be used by many users. Includes
administrative commands, shared files, library files, and others
/var
12 Typically contains variable-length files such as log and print files and any other type of
file that may contain a variable amount of data
/sbin
13 Contains binary (executable) files, usually for system administration. For
example, fdisk and ifconfig utlities
14 /kernel
Contains kernel files.
• /media:
The /media directory is used to mount removable media such as CDs, DVDs, and USB
drives.
• /opt:
The /opt directory is used to store additional software packages that are not part of the core
system.
• /run:
The /run directory contains temporary files that are created by system services and daemons.
The /srv directory is used to store data for services provided by the system.
• /sys:
The /sys directory is a virtual file system that provides information about the system's
hardware and devices.
Navigating the File System
1 cat filename
Displays a filename
2 cd dirname
Moves you to the identified directory
3 cp file1 file2
Copies one file/directory to the specified location
4 file filename
Identifies the file type (binary, text, etc)
6 head filename
Shows the beginning of a file
7 less filename
Browses through a file from the end or the beginning
8 ls dirname
Shows the contents of the directory specified
9 mkdir dirname
Creates the specified directory
more filename
10
Browses through a file from the beginning to the end
mv file1 file2
11
Moves the location of, or renames a file/directory
pwd
12
Shows the current directory the user is in
rm filename
13
Removes a file
rmdir dirname
14
Removes a directory
tail filename
15
Shows the end of a file
touch filename
16
Creates a blank file or modifies an existing file or its attributes
whereis filename
17
Shows the location of a file
which filename
18 Shows the location of a file if it is in your PATH
]
System Calls in Operating System (OS):
• A system call is a way for a user program to interface with the operating system.
• The interface between a process and an operating system is provided by system calls.
➢ Types of System Calls:
➢ Process Control: Process control is the
system call that is used to direct the
processes. Some process control examples
include creating, load, abort, end, execute,
process, terminate the process, etc.
➢ Communication: Communication is a system call that is used for communication. There are some
examples of communication, including create, delete communication connections, send, receive
messages, etc.
o open()
The open() system call allows you to access a file on a file system. It allocates resources to the file and provides
a handle that the process may refer to. Many processes can open a file at once or by a single process only.
o read(): It is used to obtain data from a file on the file system. It accepts three arguments in general:
i.e. the file descriptor, buffer which stores read data and number of bytes to be read from
the file.
The file descriptor of the file to be read could be used to identify it and open it using open() before reading.
o wait()
In some systems, a process may have to wait for another process to complete its execution before proceeding.
When a parent process makes a child process, the parent process execution is suspended until the child
process is finished.
The wait() system call is used to suspend the parent process. Once the child process has completed its
execution, control is returned to the parent process.
o write():The write() system calls writes the data from a user buffer into a device such as a
file. This system call is one of the ways to output data from a program. In general, the
write system calls takes three arguments i.e. file descriptor, pointer to the buffer where
data is stored and number of bytes to write from the buffer.
o fork():
Processes generate clones of themselves using the fork() system call. It is one of the most common ways to
create processes in operating systems. When a parent process spawns a child process, execution of the parent
process is interrupted until the child process completes. Once the child process has completed its execution,
control is returned to the parent process.
o close()
It is used to end file system access. When this system call is invoked, it signifies that the program no longer
requires the file, and the buffers are flushed, the file information is altered, and the file resources are de-
allocated as a result.
o exec()
When an executable file replaces an earlier executable file in an already executing process, this system
function is invoked. As a new process is not built, the old process identification stays, but the new process
replaces data, stack, data, head, etc.
o exit()
The exit() is a system call that is used to end program execution. This call indicates that the thread execution
is complete, which is especially useful in multi-threaded environments. The operating system reclaims
resources spent by the process following the use of the exit() system function.
What Is POSIX?
POSIX stands for Portable Operating System Interface. It’s a family of standards specified by IEEE for
maintaining compatibility among operating systems. Therefore, any software that conforms to POSIX
standards should be compatible with other operating systems that adhere to the POSIX standards.
1. Standardized APIs: POSIX defines a set of standard APIs for various functionalities such as file I/O,
process control, interprocess communication, system calls, and more. By adhering to these APIs,
developers can write applications that are portable across POSIX-compliant operating systems.
2. Shell and Utilities: POSIX specifies a standard shell syntax and command-line utilities. This includes
commands like ls, cp, mv, rm, and others. It ensures that these commands have consistent behavior
across POSIX-compliant systems.
3. File System Structure: POSIX defines a standard file system structure, including directory hierarchy
and naming conventions. This helps maintain consistency in the organization of files and directories
across different Unix-like systems.
4. Process Control: POSIX specifies standards for process creation, termination, and control. This
includes fork/exec semantics, signals, and process groups.
5. Threads: POSIX defines a threading model that includes functions for creating, synchronizing, and
managing threads.
6. Interprocess Communication: POSIX provides standards for interprocess communication
mechanisms such as message queues, semaphores, and shared memory.
7. Environment Variables: POSIX specifies a set of standard environment variables that convey
information about the system and the user's environment.
8. Regular Expressions: POSIX defines a standard for regular expressions that is used in various
utilities and programming languages.
9. Networking: While the original POSIX standard focused more on single-user systems, subsequent
revisions, such as POSIX.1b and POSIX.1g, introduced features related to networking and real-time
systems.
Single user operating system is also known as a single-tasking operating system, and a single-user
operating system is designed especially for home computers. A single user can access the computer at a
particular time. The single-user operating system allows permission to access your personal computer at
a time by a single user, but sometimes it can support multiple profiles.
Super User A superuser gets all the powers of Superuser does not exist for a multi-user
maintaining the system and making operating system as each entity has control
changes to ensure the system runs over their working.
smoothly.
Performance Only one task at one time gets Schedules different tasks for performance at
performed. any rate.
Example MS-DOS, Windows 95, Windows NT, Mainframes, IBM AS400, Linux & Unix
Windows 2000, Personal Computers, Distributed OS, etc.
etc.
o Single-User Single-Tasking: Operating system allows a single user to execute one program at a
particular time. This operating system is designed especially for wireless phones and two -way
messaging. Some functions such as printing a document, and downloading images and videos are
performed in one given frame.
Example: MS-DOS, Palm OS (Used in Palm-held computers).
o Single-User Multi-Tasking: Operating system allows a single user to execute multiple programs
at the same time, the single user can perform multiple tasks at a time. This type of operating system
is found on personal desktops and laptops. This single-user multi-tasking can be pre-emptive or
cooperative.
• Pre-emptive: The operating system shares the central processing time by dedicating a single
slot to each of the programs.
• Co-operative: This is attained by relying on each process to give time to other methods in a
defined manner. Some example taking photos while capturing video, a user can perform different
tasks such as making calculations in excel sheets.
Example: Windows, Mac
1. Interpreting users commands: It takes the instructions from the user and passes them on to the
rest of the operating system. This is the part of the OS that the user interacts with to give instructions
to the computer. It can be command-driven, menu-driven or a GUI, which may use a WIMP system.
2. File management: It controls the organization of backing storage. It uses part of the disc as a file
catalogue, which holds details of where data is stored on the disc. Files are organized into a
hierarchical filing system storing files in separate directories and subdirectories.
3. Memory management: It controls where programs and data are placed in the main memory. Many OS's
allow more than one program to be in memory at the same time. Memory management ensures that
any program does not overwrite any other program (including the OS itself).
4. Input/output management: It communicates between the computer system and the input and output
devices. It handles the transfer of data between peripherals and the CPU.
5. Resource Allocation: The OS allocates resources to other programs such as applications. For example:
o Memory management - e.g. Virtual memory paging, swapping memory contents to hard disc.
cd [directory]
unset VARIABLE
9. export: Sets the value of an environment variable.
export VARIABLE=value
10. source or dot: Executes commands from a file in the current shell session.
source filename
or
. filename
11. type: Displays information about a command, whether it's a shell built-in, an alias, or an external
command.
type command_name
bg %job_number
fg %job_number
1. ls (List): Lists the files and directories in the current directory or a specified directory.
ls
2. cp (Copy): Copies files or directories.
cp source destination
mv source destination
rm file
cat filename
ps
kill process_id
mkdir directory_name
rmdir directory_name
man command_name
1. -a option in uname
It prints all the system information in the following order: Kernel name, network node hostname, kernel
release date, kernel version, machine hardware name, hardware platform, operating system.
Syntax:
uname -a
2. -s option in uname
It prints the kernel name.
Syntax:
uname -s
3. -n option in uname
It prints the hostname of the network node(current computer).
Syntax:
uname -n
4. -r option in uname
It prints the kernel release date.
Syntax:
uname -r
5. -v option in uname
It prints the version of the current kernel.
Syntax:
uname -v
6. -m option in uname
It prints the machine hardware name.
Syntax:
uname -m
7. -p option in uname
It prints the type of the processor.
Syntax:
uname -p
8. -i option in uname
It prints the platform of the hardware.
Syntax:
uname -i
9. -o option in uname
It prints the name of the operating system.
Syntax :
uname -o
(tty):
In Unix-like operating systems, the file name associated with the terminal connected to the standard input
(tty) is typically /dev/tty. This special file represents the terminal device, and reading from or writing to
/dev/tty is a way to interact with the terminal.
For example, you can use the /dev/tty file in a script or command to prompt the user for input from the
terminal: Syntax of `tty` Command
tty [OPTION]....
#!/bin/bash
echo "Enter your name:"
read name
echo "Hello, $name! You are interacting with $(tty)."
OPTIONS
Tag Description
-m Display monday as the first day of the week.
-j Display julian dates (days one-based, numbered from January 1).
-y Display a calendar for the current year.
$ date
Wed Aug 5 15:02:59 IST 2020
$ date -u
Wed Aug 5 09:35:18 UTC 2020
3. Display a given string in date format. Note, this does not affect the systems' actual date and time value.
$ date --date=20200810
Mon Aug 10 00:00:00 IST 2020
$ date --date='now'
Wed Apr 14 13:51:45 IST 2021
9. To print the date of the day three months and two days hence (from today).
10. Use --file option to show date mentioned on each line of the file in the DATEFILE. Let us have a DATEFILE
as datefile.txt
$ cat datefile.txt
next month
Sept 23, 2020
today
next monday
$ date --file=datefile.txt
Sat Sep 5 16:08:05 IST 2020
Wed Sep 23 00:00:00 IST 2020
Wed Aug 5 16:08:05 IST 2020
Mon Aug 10 00:00:00 IST 2020
12. To print the current weekday, full month name and the day of the month:
9. Print "Hello All": For printing text "Hello All!" on the terminal, we can use the below command:
10. Print specific types of files: For example, if we wish to print every '.c' file, we can apply the below command:
Syntax:
bc [ -hlwsqv ] [long-options] [ file ... ]
o Options:
-h, {- -help } : Print the usage and exit
-i, {- -interactive } : Force interactive mode
-l, {- -mathlib } : Define the standard math library
-w, {- -warn } : Give warnings for extensions to POSIX bc
-s, {- -standard } : Process exactly the POSIX bc language
-q, {- -quiet } : Do not print the normal GNU bc welcome
-v, {- -version } : Print the version number and copyright and quit
1. Arithmetic Operators
Examples:
Input : $ echo "12+5" | bc
Output : 17
Input : $ echo "10^2" | bc
Output : 100
How to store the result of complete operation in variable?
Example:
Input:
$ x=`echo "12+5" | bc`
$ echo $x
Output:17
Output: 10
Output: 100
How to store the result of complete operation in variable?
Example:
Input:
$ x=`echo "var=500;var%=7;var" | bc`
$ echo $x
Output:3
Output: 11
Output: 10
Output: 1
Output: 0
6. Logical or Boolean Operators
Logical operators are mostly used in conditional statements. The result of the logical operators is
either 1(TRUE) or 0(FALSE).
• expr1 && expr2 : Result is 1 if both expressions are non-zero.
• expr1 || expr2 : Result is 1 if either expression is non-zero.
• ! expr : Result is 1 if expr is 0.
Examples:
Input: $ echo "10 && 5" | bc
Output: 1
Output: 0
Output: 1
Syntax:
if(condition) {statements} else {statements}
Example:
Input: $ echo 'n=8;m=10;if(n>m) print "n is greater" else print "m is greater" ' | bc -l
Output: m is greater
10. Iterative statements : bc command supports the for loop and while loop for doing iterations.
Syntax:
for(assignment; condition; updation)
{
statements.....
.......
........
}
OR
while(condition)
{
statements.....
.......
........
}
Examples:
Input: $ echo "for(i=1; i<=10; i++) {i;}" | bc
Output:
1
2
3
4
5
6
7
8
9
10
Input: $ echo "i=1;while(i<=10) {i; i+=1}" | bc
Output:
1
2
3
4
5
6
7
8
9
10
10. Functions : Functions provide a method of defining a computation that can be executed later.
Functions in bc always compute a value and return it to the caller. Function definitions are “dynamic” in the
sense that a function is undefined until a definition is encountered in the input. That definition is then used
until another definition function for the same name is encountered. The new definition then replaces the
older definition.
Syntax:
define name (parameters)
{
statements.......
.......
........
return statement
➢ Change or set Password: The passwd command changes passwords for user accounts.
output:
$ passwd
Changing password for ubuntu.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Example-2:
Change the password for the user named username: $ sudo passwd username
output:
Example-3:
Check the status of the password for the user named user1: $ sudo passwd -S user1
output:
Linux passwords by default never expire for any users. But, we can also force the users for changing the
password they log in by CLI or GUI methods next time. The syntax is as follows:
1. $ sudo passwd -e {username}
2. $ sudo passwd --expire {username}
Let us expire the password of an account immediately, we can use the following command:
• Lock password:
Example-7:
Expire user1's password. The next time he logs in, he will be required to set a new password.
output:
➢ `who` Command:
The who command is used to get information about currently logged-in users on the
system.
Syntax of who Command:
who [options] [filename]
➢ Examples of who Command
1. The who command displays the following information for each user currently logged in
to the system if no option is provided :
1. Login name of the users
2. Terminal line numbers
3. Login time of the users into the system
4. The remote host name of the user
hduser@mahesh-Inspiron-3543:~$ who
hduser tty7 2018-03-18 19:08 (:0)
2. To display host name and user associated with standard input such as keyboard
hduser@mahesh-Inspiron-3543:~$ who -m -H
NAME LINE TIME COMMENT
3. To show all active processes which are spawned by INIT process
hduser@mahesh-Inspiron-3543:~$ who -p -H
NAME LINE TIME PID COMMENT
4. To show status of the users message as +, – or ?
hduser@mahesh-Inspiron-3543:~$ who -T -H
NAME LINE TIME COMMENT
hduser + tty7 2018-03-18 19:08 (:0)
5. To show list of users logged in to system
hduser@mahesh-Inspiron-3543:~$ who -u
hduser tty7 2018-03-18 19:08 01:16 3357 (:0)
6. To show time of the system when it booted last time
hduser@mahesh-Inspiron-3543:~$ who -b -H
NAME LINE TIME PID COMMENT
system boot 2018-03-18 19:07
7. To show details of all dead processes
hduser@mahesh-Inspiron-3543:~$ who -d -H (NO dead process in this case)
NAME LINE TIME IDLE PID COMMENT EXIT
NAME LINE TIME IDLE PID COMMENT EXIT
8. To show system login process details
hduser@mahesh-Inspiron-3543:~$ who -l -H
NAME LINE TIME IDLE PID COMMENT
LOGIN tty1 2018-03-18 19:07 3073 id=tty1
9. To count number of users logged on to system
hduser@mahesh-Inspiron-3543:~$ who -q -H
hduser
# users=1
10. To display current run level of the system
hduser@mahesh-Inspiron-3543:~$ who -r
run-level 5 2018-03-18 19:07
11. To display all details of current logged in user
hduser@mahesh-Inspiron-3543:~$ who -a
system boot 2018-03-18 19:07
LOGIN tty1 2018-03-18 19:07 3073 id=tty1
run-level 5 2018-03-18 19:07
hduser + tty7 2018-03-18 19:08 01:13 3357 (:0)
12. To display system’s username
hduser@mahesh-Inspiron-3543:~$ whoami
hduser
13. To display list of users and their activities
hduser@mahesh-Inspiron-3543:~$ w
20:39:20 up 1:32, 1 user, load average: 0.09, 0.06, 0.07
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
hduser tty7 :0 19:08 1:32m 38.95s 0.19s /sbin/upstart -
14. To display user identification information
hduser@mahesh-Inspiron-3543:~$ id
uid=1001(hduser) gid=1001(hadoop) groups=1001(hadoop), 27(sudo)