Home.............Unix a view.......... Unix porgram........DBMS.............basic computer tutor............microprocessor 8085..........Student part time jobs..........Colleges in Tamilnadu.............website park
Home
Hello Friends,
I am launching these blog for the students as a guiding aspect. In this blog you can clarify your doubts about c/c++,unix,os, DBMS, microprocessor. I am going to publish many complicated programs such as sjf preemptive algorithm and micro processor programs which will help you in lab programs. Here I have mentioned some part time jobs for student also. I referred some contents from other resources, So I should say thanks to them.

This blog will be updated by many programs like anna university question papers, c and c++ programs, Many projects on c,c+= and micro processor,etc. I hope that this will be a helpful blog for you. Especially this will help for the anna university students.
I need your cooperation and valuable feed backs, Which will help me to improve my self. You can send your suggestions to
studentsevice@gmail.com
.

"All the best"
Thank you.

unix a view

Study of Unix Operating System


The UNIX Operating System:
UNIX is a popular operating system, developed by AT&T in 1969 and it has been very important to the development of the Internet. It is a multi-processing, multi-user, family of operating systems that run on a variety of architectures. UNIX allows more than one user to access a computer system at the same time.

The UNIX system is mainly composed of three different parts:
1 The Kernel
2 The File System and
3 The Shell.

The kernel is that part of the system which manages the resources of whatever computer system it lives on, to keep track of the disks, tapes, printers, terminals, communication lines and any other devices.

The file system is the organizing structure for data. The file system is perhaps the most important part of the UNIX operating system. The file system goes beyond being a simple repository for data, and provides the means of organizing the layout of the data storage in complex ways.

The shell is the command interpreter. Although the shell is just a utility program, and is not properly a part of the system, it is the part that the user sees. The shell listens to your terminal and translates your requests into actions on the part of the kernel and the many utility programs.
One can imagine the UNIX system as a series of three concentric circles, with the inner circle representing the kernel, the second circle representing the programming shell, and the last one representing application programs.




The Connection between Unix and C:

At the time the first Unix was written, most operating systems developers believed that an operating system must be written in an assembly language so that it could function effectively and gain access to the hardware. Not only was Unix innovative as an operating system, it was ground-breaking in that it was written in a language (C) that was not an assembly language. The C language itself operates at a level that is just high enough to be portable to variety of computer hardware. A great deal of publicly available Unix software is distributed as C programs that must be complied before use. Many Unix programs follow C's syntax. Unix system calls are regarded as C functions. What this means for Unix system administrators is that an understanding of C can make Unix easier to understand.

Why Use Unix?

One of the biggest reasons for using Unix is networking capability. With other operating systems, additional software must be purchased for networking. With Unix, networking capability is simply part of the operating system. Unix is ideal for such things as world wide e-mail and connecting to the Internet.

Unix was founded on what could be called a "small is good" philosophy. The idea is that each program is designed to do one job well. Because Unix was developed different people with different needs it has grown to an operating system that is both flexible and easy to adapt for specific needs.

Unix was written in a machine independent language. So Unix and unix-like operating systems can run on a variety of hardware. These systems are available from many different sources, some of them at no cost. Because of this diversity and the ability to utilize the same "user-interface" on many different systems, Unix is said to be an open system.

Basic Characteristics of Unix:

Unix is, at its base level, a multi-user, multitasking, virtual memory operating system that runs on a wide variety of hardware platforms. This means that Unix is able to do many things at the same time, for many different users, and using more memory than it really has physically installed. From a user's perspective this is very nice, and from an operating systems point of view, it is very interesting. But UNIX really is much more than just an operating system; it is a philosophy of using and programming a computer that gets its power from the relationships between programs rather than the programs themselves. This is evident from many of the design points of UNIX, which will be
mentioned later.

Let's look at each of the three characteristics of Unix listed above.

a) Unix is a multi-user system. This means that inherent to Unix is the idea that there are different users of the system, and that different users may have different sorts of privileges and types of access to different parts of the system. It allows for the idea that some users may want to protect some of their data from being accessed by other users on the system. So, in being a multi-user system, the basic ideas of system security and data privacy come up. Likewise, there must be some way to identify one user from another in a multi-user system. Unix uses a system of login names to identify users and passwords to authenticate that a user is, in fact, who she claims to be.

b) Unix is a multitasking system. This means that Unix has the ability to handle
more than one task at a time. These tasks might be several programs that any particular user wants to run, or they may be programs run by several users at once. Multitasking, combined with being a multi-user system, makes it possible for more than one person to be logged in and using a Unix system at once. This is true for any Unix system, not just large timesharing systems. Even small, desktop systems have the capability to support multiple concurrent users. Additionally, some of the tasks that the system could be doing, and probably is doing, can be system tasks related to keeping the system going and providing the services needed by the users.

c) Unix is a virtual memory operating system. The concept of virtual memory and
memory management is a bit beyond the scope of this seminar, but a few key concepts are important to note. In a virtual memory system, the system behaves as if it has much more memory than is physically installed. Some portion of the disk is used to simulate extra memory. This idea makes it possible to run large programs on a smaller system. Some tradeoff exists between the amount of memory that a program uses and how fast it will run, since if it is very large, it must access the disk a lot, but it will eventually run. In a multitasking environment, tasks that are not currently running can be moved out of memory and onto disk to free up memory for tasks that more urgently need it. The overall result is better use of the system resources for all involved.

The Unix operating system :

Unix is a time sharing operating system (OS), which consist of kernel, filesystem, shell and a collection of tools and
utilities.

The characteristic features of the Unix OS:

1. Written in C - easy understanding and portability of code i.e., can run on micros to mainframes
2. Interactive - has a consistently good user interface
3. Based on the philosophy of primitives to build complex programs
4. Easy to implement and maintain - hierarchical file system incorporating de-mountable volumes -
5. Easy application development - consistent format for byte streams/files
6. Simple and consistent interface to peripheral devices (treated as files ) - compatible file, device and interprocess I/O
7. Supports multi-user and multi-processor modes
8. Easier to write portable programs - hides machine architecture from the user -
9. Support any language that has an interpreter or compiler
10. Can initiate asynchronous processes

In general, like any OS, Unix provides the following two classes of services:

1. User services - shell, mail, text-processing, source code control system (SCCS)etc.
2. System calls - Operating system services for application development

Unix system architecture

Unix follows a layered approach that facilitates easy interaction between the different modules of the OS

Layer 1: This layer is the hardware over which the OS layers are built. This layer is not a part of Unix OS

Layer 2: This layer is the kernel part of OS which interacts directly with the hardware providing common services to programs and insulating them from hardware idiosyncrasy. It is a program that monitor and controls the resources of a computer and allocates them among its users in an optimal manner.

Layer 3: This layer contains programs that interact with the kernel by invoking a well-defined set of system calls. Typically, these programs are Unix commands like ex, wc, grep etc., and may include certain user-developed programs also.

Layer 4: This layer contains other application programs that have built on the lower levels like SCCS.


Basic Unix Commands

BASIC COMMANDS:

Date Command :

Displays the current day’s date and time

Syntax: date [option]
Output: Tue Jan 22 12:05:31 IST 2005

Who command :

Who command displays all list of users who have logged on
the systems.

Syntax: who [option]
Output: m04ee01 pts/48 Feb 22 11:16 <192.168.2.21>
m04ee02 pts/48 Feb 22 11:16 <192.168.2.21>

Who am I :

It shows the details of the user who have logged on the particular
machine

Syntax : whoami
Output : m04ee02 pts/48 Feb 22 11:16 <192.168.2.21>

echo command :

The command is used to display the output on the screen
Syntax : echo [option] string
Example: echo Unix Programming
Output : Unix Programming

Cal Command :


The command displays the calender details

Syntax: cal [month] [year]
Output: cal 2 2005
February 2005
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28

To Create a File:

Syntax: $ cat [option] >
Ex: $ cat > file1
Hello..
This is my first File
Have a Nice Day
Bye
Ctrl+d (Save)

To View an already existing File:

Syntax: $ cat
Ex: $ cat file1

To append data to an existing file:

Syntax: $ cat >>
Ex: $ cat >> file1

To Create a Multiple file with help of cat command:


Syntax: $ cat
Ex: $ cat >f1 >f2 >f3 >f4
Hello....
This is file number f4
We create multiple files
Ex: $ cat file1 file2>file3
File1 and file2 are concaténated in file3

Display the record number to the particular file:

Syntax: $ cat [option]
Ex: $ cat -n file1

To ignore the blank Records:

Syntax: $ cat [option]
Ex: $ cat -b file1

Create a Hidden file:

Syntax: $ cat [option]
Ex: $ cat >.file1

Create a Directory:


Syntax: $ mkdir [option]
Ex: $mkdir raju

To Display present working Directory:


Syntax: $ pwd
Ex: $ pwd
/home/m08cs272

To Change the Directory


Syntax: $ cd
Ex: $ cd raju

To Move parent Directory (root):


Syntax: $ cd /
Ex: $ cd /

To Create a Hidden Directory

Syntax: $ mkdir [option]
Ex: $ mkdir .venkat

To Remove a file:

Syntax: $ rm [option]
Ex: $ rm kiran

To Remove Multiple Files:

Syntax: $ rm [option]
Ex: $ rm f1 f2 f3 f4


To Remove Directory:


Syntax: $ rmdir [option]
Ex: $ rmdir sagar

To Remove all file:

Syntax: $ rm *
Ex: $ rm *

List Commends:


$ ls : It is a command to list the files and directories in
the present working Directory

$ ls - a : It is a command to display all files and
Directories including hidden files and Directories

$ ls * : List information about the Files (the current
directory by default). Sort entries alphabetically

$ ls -s : It Displays the sizes in blocks (Files &
Directories)

$ ls -l : It Displays the long listing files and
directories in present working directory

$ ls -m : It Displays all files and Directories with
separated by comma (,)

$ ls -ls : It Displays all long listing Directories

$ ls --full-time : It Displays files and Directories
with total information date and time

$ ls -nl : It Displays the long listing files and
Directories according to modification Time

$ ls -rtl : It Displays the file and Directories
with reverse order

$ ls -r : It Displays the all files and Directories
Regressively (order by order)

$ ls -l : It Displays the files and Directories in a
single column (vertical)

$ ls -x : It Displays the files and Directories with
multiple columns


Copy Commends :


1. File to a File
2. File to a Dictionary
3. Directory to Directory

1.File to File


Syntax : $cp
Ex : $cp venkat amar
..... New file
Ex : $cp venkat john
Existing file
Note: The content of john file overwrite with venkat


2. File to Directory


Syntax :$ cp
Ex : $ cp venkat ajay
.... ajay is Directory

3. Directory to Directory


Syntax : $ cp
Ex : $ cp -r Mody Venkat
Note : It copies the Directory to Directory (including all files and Directories)

Move commands


1. File to a File
2. File to a Dictionary
3. Directory to Directory

1. File to File

Syntax: $ mv [option]
Ex: $ mv file1 file2

2. File to Directory

Syntax: $ mv [option]
Ex: $ mv file1 Dir1
Note: The file1 moves to Directory (Dir1)

3. Directory to Directory


Syntax: $ mv [option] Directory>
Ex: $ mv Dir1 Dir2
Note: The content of Dir1 moves to Dir2



WC command:


The command is used to count the number of
Lines, characters, characters in the given file
Options:
l– Count the number of lines
w- Count the number of words
c-Count the number of characters

Syntax : wc [options] filename
Sample Input : wc pgm1
Output : 2 5 25 pgm1

Grep Command:


The command is used to search for a particular
pattern and displays the lines that has the particular pattern.

Syntax : grep [option] pattern filename
Sample Input : grep $a pgm1
Output : $a=10

The grep –v option will display the lines that does not
match the pattern

Sort Command:

The command is used to sort the contents of the
specified file

Syntax : sort [options] filename
Sample input: sort pgm
aa
bb

sort –r pgm
bb
aa


Cmp Command:

The command is used to compare the two files and displays the line and character where the first difference occurs.

Syntax : cmp filename1 filename2
Output: line 2 character 4

Head Command:


The command is used to display the first ten lines of the file.

Syntax : head [options] filename
Output : hello
world
Tail Command :
The command is used to display the last ten lines of the file.

Syntax : tail [options] filename
Output : Mon Mar 23 10:31:49 IST 2009
Diff command:

The command is used to the lines differing between
the file.

Syntax : diff file1 file2
Output : >hai






Input -Output Redirection, pipes, and file permissions

COMMENDS :


Input – Output Redirection :

• Redirecting standard output to a file

Instead of having the program output appear on the terminal we may direct the output to a file

Syntax : command > filename
Sample Input: date>temp

The output of date command is placed in the file temp.If the file already exists with some content it will be erased

Syntax : command >>filename
Sample Input : date>>temp

The output of the command is appended to the already existing file

• Redirecting standard Input from a file

The Input is taken from a file rather than the standard input device
Syntax : command < file
Sample Input :sort Output: anand
brindha
Examples:

1) who >temp
wc –l
Displays the list of current users working on

2) who>temp
grep 04ee25

Searches for particular user and displays the details
If logged on

Pipes

Unix allows to combine two or more commands together
using pipes.
The output of one command becomes the input for another
command
Syntax : command1|command2|command3
Sample Input: who|sort|grep m08bec263
Displays the details of user if logged on the system.
Syntax : date | cat > filename
Output: $date | cat >f1
$cat f1
Thu Mar 12 17:35:36 IST 2009
FILE PERMISSION
Chmod Command :
The command is used to change the file permissions of
files.

The first three bits (of file permissions)represents
permission for
owner,next three for group and last three for public

r – read permission
w - write permission
x - execute permission
+ - assign a permission
- - revoke a permission

Sample Inputs : Chmod –w pgm1
Chmod g –rw pgm1
Chmod +r pgm1


Output: chmod -w f6
cat >>f6
-bash: f6: Permission denied
Tee Commend :

TEE command
The command is used to store the intermediate
results while using pipes.

Output: sort frt | tee sorted_file
ewfohwf
ugejf
worhfjhrebrfke
Sed :
The sed utility copies the named filename to the standard output, edited according to a script of commands.
Syntax : sed -e script filename
Example: sed -e s/expression/replacement/g filename
$ cat >f6
dog
wolf
$ sed -e s/dog/wolf/g f6
wolf
wolf
In this example, sed will substitute all the occurances of
"dog" with "wolf" in the file called animals.
If the expression contains a space, surround it with quotation
marks as shown in the example below:
Example: sed -e s/"wild dog"/wolf/g f6
$ sed -e s/"wild dog"/wolf/g f6
dog
wolf
"wolf"
Here is another example of a script command:
sed -e y/string1/string2/ filename
Example: sed -e y/unix/UNIX/ f6
$sed -e y/wolf/WOLF/ f6
dOg
WOLF
"WiLd dOg"

In this example, sed will transform all the occurances of "unix"
into "UNIX". The variables string1 and string2 must have
same number of characters.
For more examples of script commands and for more
information on sed, type man sed.

Awk:

The awk utility scans each input file for lines that match any of a set of patterns specified. For each pattern specified there may be an
associated action performed.
awk 'pattern {action}' filename
The following example will print to the screen every line which
contains the pattern "dog" in the file named animals.

Example: awk '/dog/ {print}' animals

This next example will print "Found It" to the screen for every line
which starts with the pattern "Tiger" in the file named animals.

Example: awk '/^Tiger/ {print "Found It"}' animals

awk is a very powerful and complex utility. For more information
on awk, type man awk.

Output :$ awk '/dog/ {print}' f6
dog
"wild dog"
$awk '/^dog/ {print "found it"}' f6
found it


BC COMMAND :

[mit22@mcettelnet ~]$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
12+8
20
167*987
164829

CMP COMMAND :

The command is used to compare the two files and displays the line and character where the first difference occurs.

Output:
$ cat >f10
ddd
fff
ggg
$ cat >f11
ddd
fff
ggg
$ cmp f10 f11
$ cat >>f11
hhh
$ cmp f10 f11
cmp: EOF on f10
$ cat >>f10
yyy
$ cmp f10 f11
f10 f11 differ: byte 13, line 4



DIFF COMMAND :

The command is used to the lines differing between
the file.
[mit22@mcettelnet ~]$ diff f10 f11
4c4
< yyy
---
> hhh