Linux 5th Sem Evr
Linux 5th Sem Evr
Linux 5th Sem Evr
Depending on its location in name hierarchy, a domain may be called top-level, second-level or third
level. More levels of subdivision occur, but they are rare. Some list details several top-level domains:
Domain Description
org Non commercial organization. Private UUCP networks are often in this domain.
#include<sys/types.h>
#include<sys/socket.h>
The second argument is a pointer to a protocol-specific and third argument is the size of the structure.
There are three use of bind.
1. Servers register their well-known address with the system. It tells the system “this is my address
and any message receives for this address are to be given to me.” Both connections oriented
and connectionless servers need to do this before accepting client requests.
2. Client can register a specific address for itself.
3. A connectionless client need to assure that the system assigns it some unique address, so that
the other end (server) has a valid return address to send its responses to. This corresponds to
making certain an envelope has a valid return address, if we expect to get a reply from the
person we send the letter to.
The bind system call the local-addr and local-process elements of association 5-tuple.
Symbolic Links
A symbolic (or soft) link is an indirect reference to a file, similar to an “alias” in Mac OS or a “shortcut” in
Windows. Suppose you use a particular file often, but it is deeply nested in subdirectory 4 levels down
from your home directory. Rather than typing the full pathname of this file (or changing to that
subdirectory) every time you want to access it, you can create a symbolic link to it in your home directory
(or somewhere else handy). Then whenever you want to access that file,you can just access the symbolic
link instead of the file itself. For example, suppose this commonly accessed file is called
˜/personal/misc/letters/contacts. To create a symbolic link to this file called buddies in your home
directory,
you would type:
ln -s ˜/my/misc/stuff/friends ˜/buddies
Typing ls -l in your home directory would now yield an entry like the following for your symbolic link:
srw-r--r-- 1 joe joe 40 Aug 4 11:01 buddies -> /home/joe/my/misc/stuff/friends
Referring to this symbolic link (with cat, for instance) will always refer to the real file
/home/joe/my/misc/stuff/friends.
You can also use symbolic links with directories.
Linux actually supports two different kinds of links: hard and symbolic (or soft). A hard link is a direct link
to a lower level
operating system maintained entry for a file on disk, and is less flexible than a symbolic link. Using the ln
command without the -s option creates a hard link instead of a symbolic link.
/etc/passwd
All user information except the password encryption is now stored in /etc/passwd. This file
contained the password once, the reason why it continues to known by that name. The
encryption itself is stored in /etc/shadow.
Let’s take the line pertaining to oracle in /etc/passwd. There are seven fields hare and their
significance is noted below(in the order they appear in /etc/passwd):
Username- The name you use to log on to a system.
Password-no longer stores the password encryption but contain an x.
UID-The user’s numerical identification.
GID-The user’s numerical group identification.
Comment or GCOS-user details.
Home directory-The directory where the user ends up on logging in.
Login shell-The first program executed after logging in. this is usually the shell(/bin/ksh).
What is shadow password file? Why is it required?
However, this would restrict access to other data in the file such as username-to-userid
mappings, which would break many existing utilities and provisions. One solution is a "shadow"
password file to hold the password hashes separate from the other data in the world-readable
passwd file. For local files, this is usually /etc/shadow on Linux and each is readable only by
root. Virtually all recent Unix-like operating systems use shadowed passwords.
With a shadowed password scheme in use, the /etc/passwd file typically shows a character
such as '*', or 'x' in the password field for each user instead of the hashed password, and
/etc/shadow usually contains the following user information:
Analyzing system logs and identifying potential issues with computer systems.
In larger organizations, some tasks listed above may be divided among different system
administrators or members of different organizational groups.
OR
A. WHAT IS IPC?
Inter process Communication
IPC can be achieved by pipes, named pipes, message queue, semaphores, shared memory and
sockets. The first five forms of IPC are restricted to IPC between processes on the same host. The
last form is the only way that supports IPC between processes on different hosts.
PIPE :- We can think of the pipe as a special file that can store a limited amount of data in a first in
first out(FIFO) manner. On 4096 bytes. Generally, one process writes to the pipe, while another
process reads from the pipe. They are continuously filled at (written to) the “write end” and
emptied (read) from the “read end ” . The system keeps track of the current location of the last
read/write location. Data is written to one end of the pipe and read from the other. The OS provides
the synchronization between the writing and reading processes. By default, if a writing process
attempts to write a fully pipe, the system automatically blocks the process until the pipe is able to
receive the data. Likewise, if a read is attempted on an empty pipe, the process blocks until data is
available. In addition, the process block if specified pipe has been opened for reading, but another
process has not opened the pipe for writing.
Sticky Bit:- A process in UNIX runs by loading the executable file from the file system. This
means gathering all the blocks of the file which may be scattered throughout the disk and
pushing them to memory. When all active processes can’t be held in memory together,
some of them have to be transferred (swapped) to the swap partition. They are loaded into
memory when required. Thus the overheads for reading a file from the file system are quite
high, specially for large executables like vi or perl. There is a special mode of a file which
can reduce this time, and it is called the sticky bit. Sticky bit can be set using the chmod
command and can be set using its octal mode 1000 or by its symbol t.
For example to add the bit on the directory /usr/local/tmp, one would type chmod + t
/usr/local/tmp.
Only the super user can assign the sticky bit to any file with chmod
Firewall:
A firewall is a secure and trusted machine that sits between a private network and a public network. The
firewall machine is configured with a set of rules that determine which network traffic will be allowed to
pass and which will be blocked. In some large organization, you may even find a firewall located inside
their corporate network to segregate sensitive areas of the organization from other employees. Many
cases of computer crime occur from within an organization, not just from outside.
Firewall can be constructed in quite a variety of ways. The most sophisticated arrangement involves a
number of separate machines and is known as a perimeter network. Two machines act as “filters” called
chokes to allow only certain types of network traffic to pass, and between these chokes reside network
servers such as a mail gateway or a World Wide Web proxy server.
In practice, an internet firewall is more like a moat of a medieval castle than a firewall in a modern
building. It serves multiple purposes:
a)it restricts people to entering at a carefully controlled point.
Struct msqid_ds
Msg_perm Link link
Msqid structure NULL
Type=200
Type=100 Type=300
Msg_first
Length=2
Length=1 Length=3
data
data data
Msg_last
……
Msg_ctime
A new message queue is created, or an existing message queue is accessed with the msgget system call
Msgget(key_t key, int msgflag):A new message queue is created, or an existing message queue is
accessed with the msgget system call.
Msgsnd(int msqid, struct msgbuf *ptr, int length, long msgtype, int flag): we put a message on a
message queue using the msgsnd system call.
Msgrcv(int msqid, struct msgbuf *ptr, int length, long msgtype, int flag): A message is read from a
message queue using the msgsnd system call
Msgctl(int msgctl, int cmd, struct msqid_ds *buff): The msgctl syatem call provides a variety of control
operation on a message queue.
Describe the 5-entity tuple that may be used to uniquely identify a connection.
Ans: An connection defined by the 5-tuple completely specifies two processes that make up a
connection.
i) Protocol-TCP or UDP.
ii) Local host’s IP address (32-bit).
iii) Local port number (16-bit).
iv) Foreign/destination host’s IP address (32-bit).
v) Foreign/destination port number (16-bit).
In detail:
2. Once the hardware is recognized and started correctly, the BIOS loads and executes the
partition boot code from the designated boot device, which contains phase 1 of a Linux boot loader.
Phase 1 loads phase 2 (the bulk of the boot loader code). Some loaders may use an intermediate
phase (known as phase 1.5) to achieve this since modern large disks may not be fully readable without
further code.
3. The boot loader often presents the user with a menu of possible boot options. It then loads
the operating system, which decompresses into memory, and sets up system functions such as
essential hardware and memory paging, before calling start_kernel().
4. start_kernel() then performs the majority of system setup (interrupts, the rest of memory
management, device initialization, drivers, etc) before spawning separately, the idle process and
scheduler, and the Init process (which is executed in user space).
Kernel Linux
Init User-space
Operation
Operation
IPC(08):
In computing, Inter-process communication (IPC) is a set of techniques for the exchange of data
among multiple threads in one or more processes. Processes may be running on one or more
computers connected by a network. For two processes to communicate, the operating system must
provides some facilities for interprocess communication.IPC techniques are divided into methods for
message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of
IPC used may vary based on the bandwidth and latency of communication between the threads, and
the type of data being communicated.
User process
User process User process User process
Utility of IPC_CREAT(08)
POSIX Threads, or Pthreads, is a POSIX standard for threads. The standard, POSIX.1c, Threads
extensions (IEEE Std 1003.1c-1995), defines an API for creating and manipulating threads.Implementations of
the API are available on many Unix-like POSIX systems such as FreeBSD, NetBSD, GNU/Linux, Mac OS X and
Solaris, but Microsoft Windows implementations also exist. For example, the pthreads-w32 is available and
supports a subset of the Pthread API for the Windows 32-bit platform.
Telnet-tcp port 23: It commonly used protocols for remote access. However it locks any type of
confidentiality no encryption mechanism.
Zero level backup: That stores every file on a particular disk or partition. If disk even crashes,
we can rebuild the system by restoring the entire backup to a new disk.
Incremental backup: It contain only those files that have been added or modified since the last
time a more complete backup was performed. Incremental backup may be chosen to consume
backup media. It takes less time to complete.
Utility of “Finger” command: To get the details of users. It produces a list of all logged users on
the local machine. It can also provide details about a single user.
finger @hostname
finger usr@hostname
finger usr
The fstab (/etc/fstab) (or file systems table) file is a system configuration file commonly found
on Unix systems. The fstab file typically lists all available disks and disk partitions, and indicates
how they are to be initialized or otherwise integrated into the overall system's file system. fstab is
still used for basic system configuration, notably of a system's main hard drive and startup file
system, but for other uses has been superseded in recent years by automatic mounting.
The fstab file is most commonly used by the mount command, which reads the fstab file to
determine which options should be used when mounting the specified device. It is the duty of the
system administrator to properly create and maintain this file.
What is the importance of /boot partition?
A boot sector is a sector of a hard disk, floppy disk, or similar data storage device that contains
code for booting programs (usually, but not necessarily, operating systems) stored in other parts
of the disk. On an IBM PC compatible machine, the BIOS selects a boot device, then it copies
the first sector from the device (which may be an MBR, VBR or any executable code), to address
location.
If the device is a hard disk, that will be an MBR. It is the code in the MBR which generally
understands disk partitioning, and in turn, is responsible for loading and running the VBR of
whichever primary partition is set to boot (the active partition). The VBR then loads a second-
stage bootloader from another location on the disk.
Both shared memory and message queues can be used to exchange information between processes. But
when message queues are used, when a process post a message in the queue and if another
process reads it from the queue then the queue will be empty unlike shared memory where n
number of processes can access the shared memory and still the contents remain there until its
deliberately removed. So when i want to use an IPC between processes and i want the contents to
be there until deliberately removed i feel shared memory is the option and not the message
queues.
ii) malloc() does not initialize memory after it allocates it. It just returns the pointer back to the calling
code and the calling code is responsible for initialization or resetting of the memory, most probably by
using the memset() function. On the other hand calloc() initializes the allocated memory to 0. calloc() is
obviously slower than malloc() since it has the overhead of initialization, so it may not be the best way
to allocate memory if you don't care about initializing the allocated memory to 0.
realloc()
First of all realloc() is actually a reallocation function. It is used to resize a previously allocated (using
malloc(), calloc(), or realloc()) block of memory to the desired size. Depending on whether the new size if
less or more than the original size the block may be moved to new location.
Function Prototype for realloc():
void *realloc(void *pointer, size_t size);
F_GETLK: get the first lock which blocks the lock description pointed to by a 3 rd argument, arg, taken as a
pointer to type struct flock, defined in (fentl.h). The information retrieved shall write the information
passed to fcntl() in the structure ‘flock’. If no lock is found that would present this lock being created,
then the structure shall be left unchanged except for the lock type which shall be set to F_UNLCK.
F_SETLK: set or clear a file segment lock according to the lock description pointed to by the thired
argument, arg, taken as a pointer to type struct ‘flock’, design in (fcntl.h). F_SETLK is defined in (fcntl.h).
if a shared or exclusive lock can’t be set, fcntl() shall return immediately with a return value of -1
F_SETLKW: invokes the fcntl callable service to set or release a lock on part of a file and, if another
process has a lock on some or all of the requested range, wait until the specified range is free and the
request can be completed.
-n read commands and check for syntax errors, but do not execute.
There are many other options, not often needed. Options in ksh and bash can also be
set using long names (e.g. -o noglob instead of -f). Many options are unique to ksh
or bash.
NAMED PIPES (08):- Unix provides for a second type of pipe called named pipe or FIFO. Named
pipes are similar in spirit to unnamed pipes but have additional benefits. When created named pipes
have a directory entry. With the directory entry are file access permissions and the capacity for
unrelated processes to use the pipe file. Although the FIFO has a directory entry, keep in mind the
data written to the FIFO is passed to and stored by the kernel and is
not directly written to the file system.
Named pipe can be created at the shell level (on the command line) or within a program. At
the shell level the command used to make a named pipe is mknod. It is commonly used by the
super user to generate special device files such as block and character device file. From non
privileged users, mknod can only be used to generate a named pipe.
$mkno
d
pipefil
e p
e.g. :-
$mkno
d
PIPE p
The first argument to the mknod command is the file name for the FIFO. It is common to use an
uppercase file
name to alert the user to the special nature of the file. The second argument is a lower case p , which
notifies mknod that a FIFO file is to be created.
$ ls – l PIPE
Prw_r r 1 MCA USERS 0 oct 20 10:10 PIPE
The lower case letter p at the start of the permission string indicates the file called PIPE is
FIFO .
Under most circumstances, FIFOs are created in a programming environment. The system call
to generate
FIFO in a program has the same name as the command mknod.
Int mknod (chap * path name, int node, int dev)
The pathname is a normal unix pathname, and this is the name of the FIFO. The node
argument specifies the file mode access mode most often the file is created by ORing a symbolic
constant indicating the file type with the file access permissions. The dev argument is ignored in case
of FIFO. The dev argument for mknod is used only when a character or block special file is
specified. If mknod is successful, t retuns a value of 0, otherwise it returns –1
mkfs:
mkfs is used to build a Linux file system on a device, usually a hard disk partition. filesys is
either the device name (e.g. /dev/hda1, /dev/sdb2) or the mount point (e.g. /, /usr,
/home) for the file system. blocks is the number of blocks to be used for the file system.
The exit code returned by mkfs is 0 on success and 1 on failure.
In actuality, mkfs is simply a front-end for the various file system builders (mkfs.fstype)
available under Linux. The file system-specific builder is searched for in a number of
directories like perhaps /sbin, /sbin/fs, /sbin/fs.d, /etc/fs, /etc (the precise list is defined
at compile time but at least contains /sbin and /sbin/fs), and finally in the directories listed
in the PATH environment variable.
Benefit of NAT:The primary benefit of IP-masquerading NAT is that it has been a practical solution to the
impending exhaustion of IPv4 address space. Even large networks can be connected to the Internet with
as little as a single IP address
During the boot process for Redhat 9.0 and Fedora Core systems the init command opens the
/etc/inittab file to decide what "runlevel" the system should be booted to. The /etc/inittab file is
a plain text file that can be opened with your favorite text editor.
Example:id:3:initdefault:
This tells the init process that the default run level for the system is run level 3. To change to a
different run level simply change the number and save the /etc/inittab file. Before doing this,
however, be absolutely sure you know which run level you want. Selecting the wrong runlevel
can have serious consequences.
OR
If you need to dynamically change the runlevel of linux
For example you can switch into single user mode by running the following command:
telinit S
The administrator could subsequently return to full multi-user, X graphical interface mode either by
entering:
telinit 5
Describe the file structure of unix.
UNIX has a tree-like file system starting at the highest level with a directory
called root (referred to as /). A directory on Unix is similar to a folder on a
microcomputer. The structure and content of many of the directories is similar on
various UNIX implementations. That is, the user does not decide how to set up all
of the directories. There is a preset meaning to certain directories. Directories like
bin, usr and etc contain certain system level information and are maintained by a
system administrator. The figure below displays the uppermost levels of some of
the directories.
The directory you will be most interested in is your home directory and that will
be found somewhere under the /home directory path.