RTOS UNIT-IV - Class
RTOS UNIT-IV - Class
▪ overview of Unix/Linux,
▪ Features, commands,
▪ File manipulation commands, editors,
▪ directory commands,
▪ input/output redirection,
▪ pipes and filters,
▪ file protection, process commands,
▪ about the shell
➢ Linux and Unix are famous operating systems that allow you to perform
multiple tasks and specific functions.
➢ Let’s find some major differences between Linux and Unix.
What is Linux?
✓ Linux is an open-source operating system.
✓ This OS is supported on several computer platforms and includes multiple
software features that handle computer resources, and allow you to do tasks.
✓ This operating system was launched by Linus Torvalds at the University of
Helsinki in 1991.
What is Unix?
✓ Unix is a powerful multitasking operating system that behaves like a bridge
between the user and the computer.
✓ It allows the user to perform specific functions.
✓ This operating system was launched in 1960 and was released by AT&T Bell
Labs.
Features Linux Unix
Basic Linux is an open-source operating system. This OS is Unix is a powerful and multitasking operating
Definition supported on several computer platforms and includes system that behaves like a bridge between the
multiple software features that handle computer user and the computer.
resources, and allow you to do tasks.
Launched by This operating system was launched by Linus Torvalds This operating system was launched in 1960 and
at the University of Helsinki in 1991. released by AT&T Bell Labs.
OS family It belongs to the Unix-like family. It belongs to the Unix family.
Available in It is available in multiple languages. It is available in English.
Kernel Type It is monolithic. It can be microkernel, monolithic, and hybrid.
Written in C and other programming languages. C and assembly language.
File system It supports more file systems than Unix. It also supports less than Linux.
support
Usage It is used in several systems like desktop, smartphones, Unix is majorly used on workstations and
mainframes and servers. servers.
Examples Some examples of Linux are: Fedora, Debian, Red Hat, Some examples of Unix are IBM AIX, Darwin,
Ubuntu, Android, etc. Solaris, HP-UX, macOS X, etc.
Security Linux provides higher security. Unix is also highly secured.
Price Linux is free and its corporate support is available at a Unix is not totally free. There are some Unix
price. versions that are free, other than that UNIX is
expensive.
• Introduction:
• The Unix operating system has been the darling of system-level programmers for
the past three decades.
• However, in recent years, Linux, a Unix-like open-source software, has
become very popular for both ·application software and embedded software.
• The scaled-down version of the Linux K ernel can be used as a n embedded
operating system.
• In this chapter, we will take a quick voyage into the deep ocean of Linux
Programming.
• We will study Linux architecture, various user commands and shell
programming.
• We will 'also study how Linux manages the processes and the various· system
calls used for process management.
• We will discuss the system. calls• used for inter-process communication.·
Overview of Unix/Linux:
• Unix is not just an operating system, it is a "great
programming- environment" as described by its authors.
• Unix was developed by Ken Thomson and Dennis Ritchie
beginning in 1969.
• It became the most popular operating system in the
academic community during the 1970s.
• It was commercialized in 1981 and since then, its use in
both the academic and commercial world has grown
tremendously.
• The main attractions of UNIX are:
• The main attractions of UNIX are:
•Most of the operating system was developed in a high-level language i.e. C.
• This was revolutionary during those days because, before the advent of
Unix, operating systems were developed in assembly languages.
• As very little code of Unix is written in processor-specific assembly
language, porting the operating system is very easy. As a result, Unix can be
ported to hardware built around different processors.
• The main attraction of Unix is that it provides a large number of utilities
for software development—editors, compilers, debuggers, source code
control system, utilities for string processing(awk), utilities for developing
new compilers (lex and yacc), and a very powerful user interface, the shell.
➢ But then, a good number of programmers are scared of Unix, due to some
popular myths.(Its name comes from the initials of its designers: Aho, Weinberger, and Kernighan. awk features
user-defined functions, multiple input streams, TCP/IP networking access, and a rich set of regular expressions.)
• "It is a complicated operating system": Any operating system that has many
features and utilities will appear complicated.
• If you want to learn Unix completely and only then want to start working
on projects, you may need to spend your whole lifetime learning, without
first contributing to your organization.
• So, learn the basics and then focus on problem-solving.
• "Too many options for each command": Yes, a simple command to list the
contents of a directory has nearly 20 options.
• Do not try to remember every option, it is just a waste of precious memory
of your brain.
• Look up the manual to see when you require a special option.
• Unix OS is the first OS to be developed in a high-level language, C.
• Hence, it is a portable operating system. Only a small portion of the OS
will have processor-dependent code.
• "Too many commands and utilities": It is
important to know the features supported by
Unix, and then learn only those utilities that are
required for your project.
• For example, "awk" programming language is an
excellent tool for string processing and non-time-
critical database development.
• If your project does not require such facilities,
please ignore awk!
• A number of Unix flavors are available such as AT & T Unix, HP UX, Sun
Solaris, IBM AIX, DEC Ultrix and Linux.
• Linux, developed by Linus Torvalds at the University of Helsinki, is a freely
distributed implementation of a UNIX-like kernel.
• Even the source code for the Linux kernel is freely available.
• The Linux community supports the concept of free software, promoted by Free
Software Foundation.
• Programming in a Linux environment is essentially the same as programming
in a Unix environment.
• The GNU Compiler Collection provides a number of compilers for various
languages. (GNU stands for "GNU's Not Unix“ and it is pronounced as “g-noo”. GNU is a
free and open-source operating system that was started in 1984 by Richard Stallman. GNU
is based on the Unix operating system, but it has been greatly modified over the years.)
• However, as the source code is available free of cost to everyone, many
variations of Linux are available
Features of Linux: The important features of Linux are listed below
➢ It is a multi-user operating system. Every user is given a username or login name.
➢ The system administrator logs in as 'root'. A number of users can form a 'group' and each of these groups is
given a name.
➢ The file system is organized hierarchically. At the topmost level is the root directory denoted by / under which
there will be sub-directions. Under each subdirectory, there can be directories or files.
Some important directories are:
❖ /bin contains commonly used commands
❖ /usr/bin contains less commonly used commands
❖ /etc contains the system administration commands
❖ /dev contains device files
❖ /usr/spool/mail contains mail files(Simultaneous Peripheral operations online -a computer document or task
list (or "job") is to read it in and store it)
❖ /usr contains users directories
➢ A variety of user interfaces are available. The command user interfaces are shell (sh,) kshell
(ksh) and C shell (csh). Menu-driven interface is through curses. X-Windows provides the
Graphical User Interface. (shell is the Linux command line interpreter. It provides an interface between the user and the kernel
and executes programs called commands. For example, if a user enters ls then the shell executes the ls command).(korn shell,Bourne)
➢ All devices are treated as files. In /dev directory, there will be one entry for each file. Writing
to a printer or a serial port is no different from writing to a file in the hard disk.
➢ To provide security for user's files, a user will have a password. Only the encrypted password
is stored in the system. The file /etc/passwd contains the list of all authorized users. It also
contains the encrypted passwords, default working directory of the users& their default shell.
➢ Every file is given protections—read, write and execute permissions are given to the owner,
group and others. The owner of a file can give permission to the group members and others to
read, write or execute the files.
Linux Command Summary
➢ When you login to the Unix system using the username and password given by your
system administrator, the "$" sign will be displayed. This is the system prompt.
➢ The system prompt is an indication that the system is ready to take commands from
you.
➢ After typing the command as given in the example column, you have to press enter key.
➢ If you make typing mistakes or give wrong arguments, Linux gives very cryptic error
messages. If the command is correct, the system will execute the command and display
the "$" prompt again.
➢ A command will be in the format
$commandname options arguments.
A sample command is as follows:
$nl —d hello.c
In this command, nl is the commandname, -d is the option and hello.c is the argument
Command Function Example
banner To display a banner banner prasad
cal To display calendar for a month or year cal 2004 cal 1 2004
date To display today's date date
sleep To make the shell sleep for a few seconds Sleep 10
who am i To know about your login details (sometimes you forget
who you are!)) Who am i
who To display the list of users who are
presently logged in who
• You can pass the output of one command to another command using pipes.
• When you give the shell command: $cat hello.c
the file hello.c will be displayed in one shot.
• If it is a large file, you will see only the last few lines. If you want to see few lines at a
time, you can give the command: $cat hello.c | more
• Here, the vertical line | is used for the piping operation.
• The output of the cat command is passed to the more command which displays a few
lines at a time.
• You can press the space bar or the return key to see the next set of lines.
• Alternatively, you can give the command:
$more filename
"more" is a filter that processes the input data to display a few lines at a time. In the first command, you are piping
the output of the cat filename to the "more" filter. In the second command, you are invoking the filter directly.
• The important filters that can be used directly as commands or that can be used through the pipe operation are:
sort Sorting utility. To sort a file in an order, such as alphabetical order, numerical order etc.
grep Pattern matching utility. To match patterns in strings such as to check whether a pattern exists in a file or
not.(Grep, short for “global regular expression print”, is a command used for searching and matching text patterns in files contained in the regular expressions.)
tr Translation utility. To translate upper case to lower case, remove punctuation marks, etc
prep File splitting utility, To split the file so that each word is placed in a separate line.(Prep reads each file in sequence
and writes it on the standard output, one `word' to a line. )