You are on page 1of 29

c 

        


Answer :The most common reason to put a process in the background is to allow you to do
something else interactively without waiting for the process to complete. At the end of the
command you add the special background symbol, &. This symbol tells your shell to execute the
given command in the background. Example: cp *.* ../backup& (cp is for copy)

c     


Answer :The kill command takes the PID as one argument; this identifies which process to
terminate. The PID of a process can be got using 'ps' command.

c 
  
Answer :The ps command prints the process status for some or all of the running processes.
The information given are the process identification number (PID),the amount of time that the
process has taken to execute so far etc.

c 
  
Answer :A daemon is a process that detaches itself from the terminal and runs, disconnected, in
the background, waiting for requests and responding to them. It can also be defined as the
background process that does not belong to a terminal session. Many system functions are
commonly performed by daemons, including the sendmail daemon, which handles mail, and the
NNTP daemon, which handles USENET news. Many other daemons may exist. Some of the most
common daemons are: Ȉ init: Takes over the basic running of the system when the kernel has
finished the boot process. Ȉ inetd: Responsible for starting network services that do not have
their own stand-alone daemons. For example, inetd usually takes care of incoming rlogin, telnet,
and ftp connections. Ȉ cron: Responsible for running repetitive tasks on a regular schedule.

c 
 
     
Answer :When you enter 'ls' command to look at the contents of your current working
directory, UNIX does a series of things to create an environment for ls and the run it: The shell
has UNIX perform a fork. This creates a new process that the shell will use to run the ls program.
The shell has UNIX perform an exec of the ls program. This replaces the shell program and data
with the program and data for ls and then starts running that new program. The ls program
is loaded into the new process context, replacing the text and data of the shell. The ls program
performs its task, listing the contents of the current directory.

c     
 

Answer :The system calls used for low-level process creation are execlp() and execvp(). The
execlp call overlays the existing program with the new one , runs that and exits. The original
program gets back control only when an error occurs. execlp(path,file_name,arguments..); //last
argument must be NULL A variant of execlp called execvp is used when the number of
arguments is not known in advance. execvp(path,argument_array); //argument array should be
terminated by NULL.

c 
 
    
Answer :When you execute a program on your UNIX system, the system creates a special
environment for that program. This environment contains everything needed for the system to
run the program as if no other program were running on the system. Each process has process
context, which is everything that is unique about the state of the program you are currently
running. Every time you execute a program the UNIX system does a fork, which performs a
series of operations to create a process context and then execute your program in that context.
The steps include the following: Ȉ Allocate a slot in the process table, a list of currently
running programs kept by UNIX. Ȉ Assign a unique process identifier (PID) to the process. Ȉ
iCopy the context of the parent, the process that requested the spawning of the new process. Ȉ
Return the new PID to the parent process. This enables the parent process to examine or control
the process directly. After the fork is complete, UNIX runs your program

c 
 
 
Answer :As a process executes it changes state according to its circumstances. Unix processes
have the following states: Running : The process is either running or it is ready to run . Waiting :
The process is waiting for an event or for a resource. Stopped : The process has been stopped,
usually by receiving a signal. Zombie : The process is dead but have not been removed from the
process table.

c 
 
Answer :When a program forks and the child finishes before the parent, the kernel still keeps
some of its information about the child in case the parent might need it - for example, the parent
may need to check the child's exit status. To be able to get this information, the parent calls
`wait()'; In the interval between the child terminating and the parent c alling `wait()', the child is
said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)

c      
   
Answer :A parent and child can communicate through any of the n ormal inter-process
communication schemes (pipes, sockets, message queues, shared memory), but also have some
special ways to communicate that take advantage of their relationship as a parent and child. One
of the most obvious is that the parent can get the exit status of the child

Q          


Answer :Getting the value of an environment variable is done by using `getenv()'. Setting the
value of an environment variable is done by using `putenv()'.

c !
     
Answer :System calls Description fork() To create a new process exec() To execute a new
program in a process wait() To wait until a created process completes its execution exit() To
exit from a process execution getpid() To get a process identifier of the current process
getppid() To get parent process identifier nice() To bias the existing priority of a process brk()
To increase/decrease the data segment size of a process

c " 
  
   #$%#$&#$&#$&
#'  ('$&)
Answer :"Hello World" will be printed 8 times. Explanation: 2^n times where n is the number of
calls to fork()
c * #$ 
Answer :The `fork()' used to create a new process from an existing process. The new process is
called the child process, and the existing process is called the parent. We can tell which is which
by checking the return value from `fork()'. The parent gets the child's pid returned to him, but
the child gets 0 returned to him

c +  
 , 

 -
Answer :While booting, special process called the 'swapper' or 'scheduler' is created with
Process-ID 0. The swapper manages memory allocation for processes and influences CPU
allocation. The swapper inturn creates 3 children: Ȉ the process dispatcher, Ȉ vhand and Ȉ
dbflush with IDs 1,2 and 3 respectively. This is done by executing the file /etc/init. Process
dispatcher gives birth to the shell. Unix keeps track of all the processes in an internal data
structure called the Process Table (listing command is ps -el).

c 
 

Answer :A shell is an interactive user interface to an operating system services that allows an
user to enter commands as character strings or through a graphical user interface. The shell
converts them to system calls to the OS or forks off a process to execute the command. System
call results and other information from the OS are presented to the user through an interactive
interface. Commonly used shells are sh,csh,ks etc

c  
      
Answer :The privileged mount system call is used to attach a file system to a directory of
another file system; the unmount system call detaches a file system. When you mount another
file system on to your directory, you are essentially splicing one directory tree onto a branch in
another directory tree. The first argument to mount call is the mount point, that is , a directory
in the current file naming system. The second argument is the file system to mount to that point.
When you insert a cdrom to your unix system's drive, the file system in the cdrom automatically
mounts to /dev/cdrom in your system

c           
Answer :The system call mknod creates special files in the following sequence.
kernel assigns new inode, sets the file type to indicate that the file is a pipe, directory or special
file, If it is a device file, it makes the other entries like major, minor device numbers. For
example: If the device is a disk, major device number refers to the disk controller and minor
device number is the disk.

c   
./"
Answer :Every file has following attributes: Ȉ owner's user ID ( 16 bit integer ) Ȉ owner's group
ID ( 16 bit integer ) Ȉ File access mode word 'r w x -r w x- r w x' (user permission-group
permission-others permission) r-read, w-write, x-execute To change the access mode, we use
chmod(filename,mode). Example 1: To change mode of myfile to 'rw-rw-r--' (ie. read, write
permission for user - read,write permission for group - only read permission for others) we give
the args as: chmod(myfile,0664) . Each operation is represented by discrete values 'r' is 4 'w' is
2 'x' is 1 Therefore, for 'rw' the value is 6(4+2). Example 2: To change mode of myfile to 'rwxr--
r--' we give the args as: chmod(myfile,0744).
c 
 
Answer :All UNIX files have its description stored in a structure called 'inode'. The inode
contains info about the file-size, its location, time of last access, time of last modification,
permission and so on. Directories are also represented as files and have an associated inode. In
addition to descriptions about the file, the inode contains pointers to the data blocks of the file.
If the file is large, inode has indirect pointer to a block of pointers to additional data blocks (this
further aggregates for larger files). A block is typically 8k. Inode consists of the following fields:
Ȉ File owner identifier Ȉ File type Ȉ File access permissions Ȉ File access times Ȉ Number of links
Ȉ File size Ȉ Location of the file data.

c     012


Answer :All devices are represented by files called special files that are located in/dev directory.
Thus, device files and other files are named and accessed in the same way. A 'regular file' is just
an ordinary data file in the disk. A 'block special file' represents a device with characteristics
similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device
with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).


 
  
kernel.h

To determine the various levels of messages that are defined on your system, examine the
kernel.h file.


     
      
gpasswd -r

The gpasswd command is used to change the password assigned to a group. Use the -r option to
remove the password from the group.

      
        -

 
 
find /home | cpio -o > backup.cpio

The find command is used to create a list of the files and directories contained in home. This list
is then piped to the cpio utility as a list of files to include and the output is saved to a file called
backup.cpio.

       


   
echo $SHELL

The name and path to the shell you are using is sav ed to the SHELL environment variable. You
can then use the echo command to print out the value of any variable by preceding the
variable's name with $. Therefore, typing echo $SHELL will display the name of your shell.


    
The /etc/passwd file contains all the information on users who may log into your system. If a
user account is not contained in this file, then the user cannot log in.



       
You can use rmdir or rm -rf to delete a directory. Answer a is incorrect, because the rm
command without any specific flags will not delete a directory, it will only delete files .


       
Fdisk

       
Answer: logrotate
The logrotate command can be used to automate the rotation of various logs.

1   


     
  

  3
   44444444444-

Answer: history 5
The history command displays the commands you have previously entered. By passing it an
argument of 5, only the last five commands will be displayed.


       
Answer: dmesg
The dmesg command displays the system messages contained in the kernel ring buffer. By using
this command immediately after booting your computer, you will see the boot messages.



      ! 
Answer: 2
Linux can be installed on two partitions, one as / which will contain all files and a swap
partition.



    

 
Answer: /var/log/messages
By default, the main system log is /var/log/messages.

5  
 
 3   
 -
  
  
  
tail -15 dog cat horse
The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each
specified file.



    
The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the
database is created.

5   -5    



-1  
 
 3 

444444444 -
zcat.
The zcat utility allows you to examine the contents of a compressed file much the same way that
cat displays a file.
5  
 
  

   
  
 
  -
      
 

   
which.
The which command searches your path until it finds a command that matches the command
you are looking for and displays its full path.

5     


    
 -

       -
whatis.
The whatis command displays a summary line from the man page for the specified command.

5 
  
   
   

    
    
   -

   

    -
Use the -F option.
In order to create a link to a directory you must use the -F option.


  
  63

 
   

44444444444-
type.
The first character of the permission block designates the type of file that is being displayed.


    
    4444444444
top

The top utility shows a listing of all running processes that is dynamically updated.


         
to the screen or display.
By default, your shell directs standard output to your screen or display.

5 

-

    
 7+  - -

  
   
tar xf MyBackup.tar memo.ben.
This command uses the x switch to extract a file. Here the file memo.ben will be restored from
the tarfile MyBackup.tar.

5   



   7+  - -
    
  
tar tf MyBackup.tar
The t switch tells tar to display the contents and the f modifier specifies which file to examine.
5       
 
 -
 

    
tar
You can use the z modifier with tar to compress your archive at the same time as creating it.


    
syslogd
The syslogd daemon is responsible for tracking system information and saving it to specified log
files.

5 
   

 83999-
  
  
:3999
split.
The split text filter will divide files into equally sized pieces. The default length of each piece is
1,000 lines.

5    


     -
  

   

set -o vi.
The set command is used to assign environment variables. In this case, you are instructing your
shell to assign vi as your command line editor. However, once you log off and log back in you
will return to the previously defined command line editor.


    
  ! 
root

Whenever you install Linux, only one user account is created. This is the superuser account also
known as root.

  
    

          

  ,  

repquota

The repquota command is used to get a report on the status of the quotas you have set including
the amount of allocated space and amount of used space.
1  
 3
      
readonly

You cannot run fsck on a partition that is mounted as read-write.


1       
  -

  
    
pwconv

The pwconv command creates the file /etc/shadow and changes all passwords to 'x' in the
/etc/passwd file.
+/3

    3  

  -

  
    
  
passwd boba.
The passwd command is used to change your password. If you do not specify a username, your
password will be changed.

;
    

  /
 

    
44444444444
nice.
Both the top and nice utilities provide the capability to change the priority of a running process.


  
    

  
  
  

   -
ls -r /home/ben/memos/*.mem.
The -c option used with ls results in the files being listed in chronological order. You can use
wildcards with the ls command to specify a pattern of filenames.

FTP/file server open/vulnerable (port 21)

TELNET service open/vulnerable(port 23)

SMTP relay vulnerable (port 25)

POP3/mail server vulnerable (port 110)

HTTP/web server vulnerable (port 80)

Scan for Windows file sharing susceptibility (port 445)

Scan for NETBIOS susceptibility (port 139)

Scan for firewall remote login (port 8080)

Microsoft Remote Desktop vulnerable (port 3389)

VNC Remote Desktop vulnerable (port 5900)

VPN (PPTP) service open/vulnerable (port 1723)

Microsoft SQL Server open/vulnerable (port 1433)

Oracle database service open/vulnerable (port 1521)


MySQL database open/vulnerable (port 3306)


      
  
  -

Runlevel 0 is halt
Runlevel 1 is single-user
Runlevels 2-5 are multi-user (some distro uses RUN level 5 to start X [KDE/Gnome])
Runlevel 6 is for rebooting system
Typing init 3 will move system to run level 3:

 

Display current IP address
Code:
ifconfig eth0
ifconfig -a
Set new IP to 192.168.1.10
Code:
ifconfig eth0 192.168.1.10
Set new IP to 192.168.1.10 with net mask
Code:
ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up

* <  


# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
The key line in the example above is:

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. To help with this a detailed description of the individual run
levels is outlined in the table below:

Runlevel Description
<  9
The halt runlevel - this is the runlevel at which the system shuts down. For obvious reasons it is
unlikely you would want this as your default runlevel.
<  :
Single runlevel. This causes the system to start up in a single user mode under which only the
root user can log in. In this mode the system does not start any networking or X windowing, X or
multi-user services. This run level is ideal for system administrators to perform system
maintenance or repair activities.
<  =
Boots the system into a multi-user mode with text based console login capability. This runlevel
does not, however, start the network.
<   >
Similar to runlevel 2 except that networking services are started. This is the most common
runlevel for server based systems that do not require any kind of graphical desktop
environment.
<  8
Undefined runlevel. This runlevel can be configured to provide a custom boot state.
<  ?
Boots the system into a networked, multi-user state with X Window System capability. By
default the graphical desktop environment will start at the end of the boot process. This is the
most common run level for desktop or workstation use.
<  @
Reboots the system. Another runlevel that you are unlikely to want as your default.


!1!A  B<+

LILO (LInux LOader)


LILO stores information about the location of the kernel or other operating system on the
Master Boot Record (MBR).

GNU GRUB (GRand Unified Boot loader)


GRUB has a more powerful, interactive command line interface
RUB will default to its command line interface where the user can boot the system manually.
GRUB may have difficulties booting certain hardware.
LILO and GRUB do have a number of differences:

LILO has no interactive command interface, whereas GRUB does.


LILO does not support booting from a network, whereas GRUB does.

* 1  


 

The size of the host part depends on the size of the network. To accommodate different needs,
several classes of networks, defining different places to split IP addresses, have been defined.
The class networks are described here:

Class A
Class A comprises networks 1.0.0.0 through 127.0.0.0. The network number is contained in the
first octet. This class provides for a 24-bit host part, allowing roughly 1.6 million hosts per
network.

Class B
Class B contains networks 128.0.0.0 through 191.255.0.0; the network number is in the first two
octets. This class allows for 16,320 nets with 65,024 hosts each.

Class C
Class C networks range from 192.0.0.0 through 223.255.255.0, with the network number
contained in the first three octets. This class allows for nearly 2 million networks with up to 254
hosts.
Classes D, E, and F
Addresses falling into the range of 224.0.0.0 through 254.0.0.0 are either experimental or are
reserved for special purpose use and don't specify any network. IP Multicast, which is a service
that allows material to be transmitted to many points on an internet at one time, has been
assigned addresses from within this range.

ï  
  
 6 is a linux command that will output useful information about your linux distribution,
kernel version, cpu information and more.




!  

nmap can be used to scan your machine to see whats ports are open issue the
following command to scan your computers machine nmap -sS -O 127.0.0.1

The second method was netstat. netstat can show hidden ports and what programs using
them issue the following command as root:
netstat -nap

or
? ??


  
75Cc!
? ? ?
? ? ?

to change Open /etc/my.cnf file:


ý   

Set new port 5123:



Save and close the file. Restart mysqld:

ý   


,  

ý     ý 


  

mysqladmin -h <hostname> -u <username> -p processlist


 7,

Below are notes on some of the important variables, I took down while tuning the config file.

, 4 
4
MySQL 4 provides one feature that can prove very handy - a query cache. In a situation where
the database has to repeatedly run the same queries on the same data set, returning the same
results each time, MySQL can cache the result set, avoiding the overhead of running through the
data over and over and is extremely helpful on busy servers.

4 4
The value of key_buffer_size is the size of the buffer used with indexes. The larger the buffer, the
faster the SQL command will finish and a result will be returned. The rule-of-thumb is to set the
key_buffer_size to at least a quarter, but no more than half, of the total amount of memory on
the server. Ideally, it will be large enough to contain all the indexes (the total size of all .MYI files
on the server).

 4 

The default is 64. Each time MySQL accesses a table, it places it in the cache. If the system
accesses many tables, it is faster to have these in the cache. MySQL, being multi-threaded, may
be running many queries on the table at one time, and each of these will open a table. Examine
the value of open_tables at peak times. If you find it stays at the same value as your table_cache
value, and then the number of opened_tables starts rapidly increasing, you should increase the
table_cache if you have enough memory.

4 
The sort_buffer is very useful for speeding up myisamchk operations (which is why it is set
much higher for that purpose in the default configuration files), but it can also be useful
everyday when performing large numbers of sorts.

 4 4 4
The read_rnd_buffer_size is used after a sort, when reading rows in sorted order. If you use
many queries with ORDER BY, upping this can improve performance. Remember that, unlike
key_buffer_size and table_cache, this buffer is allocated for each thread. This variable was
renamed from record_rnd_buffer in MySQL 4.0.3. It defaults to the same size as the
read_buffer_size. A rule-of-thumb is to allocate 1KB for each 1MB of memory on the server, for
example 1MB on a machine with 1GB memory.


 4 

If you have a busy server that's getting a lot of quick connections, set your thread cache high
enough that the Threads_created value in SHOW STATUS stops increasing. This should take
some of the load off of the CPU.

4 4
"Created_tmp_disk_tables" are the number of implicit temporary tables on disk created while
executing statements and "created_tmp_tables" are memory-based. Obviously it is bad if you
have to go to disk instead of memory all the time.
r i   
 i





1)Linux default shell is /bin/bash, where Unix default shell


is /bin/sh (other shell also supported)
2) Linux Store all their command history,but if the default
shell is /bin/sh in Unix, then Unix not store Co mmand history.
3) Linux support Tab key, but unix not support Tab key

i   


 
  i  
  

ANS: /proc/cpuinfo
or
$uname -m
or
/usr/bin/file

i  i  
 
 
 

rpm -qa | grep nfs


rpm -qi nfs nfs-utils
yum info nfs nfs-utils

   
 i



Telnet ->
Its just getting (Telenet) a connection to the server.
Its not more secure. Anybody can use it.
It can be easly hacked.It can be easily read by anybody in
that network

SSH -> secured shocket shell


Its more secure than Telnet .
This has an encrption and decrption of the data /usr/pwd
None can hack this. It is the good way to transfer the data

i    !


"i 
#
 

1. The system BIOS checks the system and launches the first
stage boot loader on the MBR of the primary hard disk.

2. The Frist stage boot loader loads itself into memory and
launches the second stage boot loader from the /boot/
partition.

3. The second stage boot loader loads the kernel into


memory, which in turn loads any necessary modules and
mounts the root
partition read-only.

4. The kernel transfers control of the boot process to the /


sbin/init program.

5. The /sbin/init program loads all services and user-space


tools, and mounts all partitions
listed in /etc/fstab.

6. The user is presented with a login screen for the


freshly booted Linux system.

 #
$%% 
i

alt+f1 for application menu


ctl+l to clear screen
alt+f2 to open run application window
alt+f3 for find
alt+f4 to close application
alt+f9 to minimise window
Ctrl-Alt-D Show desktop
Crtl-Alt-Backspace Restart XWindows

  

   
%

/var/log/messages system log messages can be seen here


/var/log/dmesg Kernel boot log messages can view

There are Three centralized loggin demons


1)syslogd
2)klogd
3)auditd

klogd:- collect log file created by the Kernel


syslogd:- Collect log file created by the system
auditd:- Collect log file created by the SELinux

After collecting the log system store logs on different location

  

 & & i'

1. Username: It is used when user logs in. It should be between 1 and 32 characters in
length.
2. Password: An x character indicates that encrypted password is stored in /etc/shadow
file.
3. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved
for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999
are reserved by system for administrative and system accounts/groups.
4. Group ID (GID): The primary group ID (stored in /etc/group file)
5. User ID Info: The comment field. It allow you to add extra information about the users
such as user's full name, phone number etc. This field use by finger command.
6. Home directory: The absolute path to the directory the user will be in when they log in.
If this directory does not exists then users directory becomes /
7. Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is
a shell. Please note that it does not have to be a shell.

('i% 
   %
ls - list directory contents
ls -l (-l use a long listing format)

('i% 
   %)
 
  

ls -a (-a, do not hide entries starting with .)

('i% 
      
%



ps -f (-f does full-format listing.)

('i% 
       
%


     
 
ps -au Myname (-u by effective user ID (supports names)) (a - all users)

('i%   


kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
kill -9 -1 (Kill all processes you can kill.)
killall - kill processes by name most (useful - killall java)

Q.  i %  i 



 
less filename
cat filename
pg filename
pr filename
more filename
most useful is command: tail file_name - you can see the end of the log file.

('i% 
   %
ls - list directory contents
ls -l (-l use a long listing format)

('i% 
   %)
 
  

ls -a (-a, do not hide entries starting with .)

('i% 
      
%



ps -f (-f does full-format listing.)

('i% 
       
%


     
 
ps -au Myname (-u by effective user ID (supports names)) (a - all users)

('i%   


kill -9 8 (process_id 8) or kill -9 %7 (job number 7)
kill -9 -1 (Kill all processes you can kill.)
killall - kill processes by name most (useful - killall java)
Q.  i %  i 

 
less filename
cat filename
pg filename
pr filename
more filename
most useful is command: tail file_name - you can see the end of the log file.

i%  %  


* 

+
ln /../file1 Link_name
Links create pointers to the actual files, without duplicating the contents of
the files. That is, a link is a way of providing another name to the same file.
There are two types of links to a file:Hard link, Symbolic (or soft) link;

 %
Sum of all directories called file system.
A file system is the primary means of file storage in UNIX.
File systems are made of inodes and superblocks.

i%  *%+


By storing and manipulate files.

('i%    ,      *


 
+
du -s
df

The du command summarizes disk usage by directory. It recurses through all


subdirectories and shows disk usage by each subdirectory with a final total at the end.

  
i 
%   


Answer:

When you enter 'ls' command to look at the contents of your current working directory,
UNIX does a series of things to create an environment for ls and the run it: The shell has
UNIX perform a fork. This creates a new process that the shell will use to run the ls
program. The shell has UNIX perform an exec of the ls program. This replaces the shell
program and data with the program and data for ls and then starts running that new
program. The ls program is loaded into the new process context, replacing the text and
data of the shell. The ls program performs its task, listing the contents of the current
directory.

 -


Answer:

A daemon is a process that detaches itself from the terminal and runs, disconnected, in
the background, waiting for requests and responding to them. It can also be defined as
the background process that does not belong to a terminal session. Many system
functions are commonly performed by daemons, including the sendmail daemon, which
handles mail, and the NNTP daemon, which handles USENET news. Many other
daemons may exist. Some of the most common daemons are:

init: Takes over the basic running of the system when the kernel has finished the boot
process.

inetd: Responsible for starting network services that do not have their own stand -alone
daemons. For example, inetd usually takes care of incoming rlogin, telnet, and ftp
connections.

cron: Responsible for running repetitive tasks on a regular schedule.

   


 

The ps command prints the process status for some or all of the running processes. The
information given are the process identification number (PID),the amount of time that the
process has taken to execute so far etc.

 

 
  
   


The most common reason to put a process in the background is to allow you to do
something else interactively without waiting for the process to complete. At the end of the
command you add the special background symbol, &. This symbol tells your shell to
execute the given command in the background.

 ./       

The term IPC (Inter-Process Communication) describes various ways by which different
process running on some operating system communicate between each other. Various
schemes available are as follows: Pipes:
One-way communication scheme through which different process can communicate. The
problem is that the two processes should have a common ancestor (parent-child
relationship). However this problem was fixed with the introduction of named-pipes
(FIFO).

Message Queues :

Message queues can be used between related and unrelated processes running on a
machine.

Shared Memory:

This is the fastest of all IPC schemes. The memory to be shared is mapped into the
address space of the processes (that are sharing). The speed achieved is attributed to
the fact that there is no kernel involvement. But this scheme needs synchronization.
Various forms of synchronisation are mutexes, condition-variables, read-write locks,
record-locks, and semaphores.
   
 i
i 

.


Swapping: Whole process is moved from the swap device to the main memory for
execution. Process size must be less than or equal to the available main memory. It is
easier to implementation and overhead to the system. Swapping systems does not
handle the memory more flexibly as compared to the paging systems.

Paging:

Only the required memory pages are moved to main memory from the swap device for
execution. Process size does not matter. Gives the concept of the virtual memory.

   $



0
%1ii  
i 
 
   i  

Kernel follows Round Robin scheme choosing a swap device among the multiple swap
devices in Unix System.

   



 % $
    
i   
 
 %

When Kernel swaps the process out of the primary memory, it performs the following:
Kernel decrements the Reference Count of each region of the process. If the reference
count becomes zero, swaps the region out of the main memory,
Kernel allocates the space for the swapping process in the swap device,
Kernel locks the other swapping process while the current swapping operation is going
on,
The Kernel saves the swap address of the region in the region table.

 % 
 % 2 *   +  2  

This contains the private data that is manipulated only by the Kernel. This is local to the
Process, i.e. each process is allocated a u-area.

   


  i   
 %i i 
 
   
 %

All memory space occupied by the process, process¶s u-area, and Kernel stack are
swapped out, theoretically. Practically, if the process¶s u-area contains the Address
Translation Tables for the process then Kernel implementations do not swap the u-area.

 3 i 

fork() is a system call to create a child process. When the parent process calls fork()
system call, the child process is created and if there is short of memory then the child
process is sent to the read-to-run state in the swap device, and return to the user state
without swapping the parent process. When the memory will be available the child
process will be swapped into the main memory.

 4 

i 

At the time when any process requires more memory than it is currently allocated, the
Kernel performs Expansion swap. To do this Kernel reserves enough space in the swap
device. Then the address translation mapping is adjusted for the new virtual address
space but the physical memory is not allocated. At last Kernel swaps the process into the
assigned space in the swap device. Later when the Kernel swaps the process into the
main memory this assigns memory according to the new address translation mapping.

i i  i 

The swapper is the only process that swaps the processes. The Swapper operates only
in the Kernel mode and it does not uses System calls instead it uses internal Kernel
functions for swapping. It is the archetype of all kernel process.

       


    % i  56
'

Zombie process: They do not take any up physical memory.


Processes locked in memories that are updating the region of the process.
Kernel swaps only the sleeping processes rather than the µready-to-run¶ processes, as
they have the higher probability of being scheduled than the Sleeping processes.

- 
 i
  *+
 *+% 

During the fork() system call the Kernel makes a copy of the parent process¶s address
space and attaches it to the child process. But the vfork() system call do not makes any
copy of the parent¶s address space, so it is faster than the fork() system call. The child
process as a result of the vfork() system call executes exec() system call. The child
process from vfork() system call executes in the parent¶s address space (this can
overwrite the parent¶s data and stack ) which suspends the parent process until the child
process
exits.

4 
 
% 0
%'

The most widely used are: 1. System V (AT&T) 2. AIX (IBM) 3. BSD (Berkeley) 4. Solaris (Sun)
5. Xenix ( A PC version of Unix)

4 


 '

Kernal: It carries out basic operating system functions such as allocating memory, accessing files
and handling communications.

Shell:A shell provides the user interface to the kernel.There are 3 major shells : C-shell, Bourne
shell , Korn shell

 


ex is Unix line editor and vi is t he standard Unix screen editor.

   %  %    i     % 


(1)/bin: contains many programs which will be executed by users (2)/etc : files used by
administrator (3)/dev: hardware devices (4)/lib: system libraries (5)/usr: application software
(6)/home: home directories for different systems.

   7  8 




Answer:

µgrep¶ is a pattern search command. It searches for the pattern, specified in the command line
with appropriate option, in a file(s).

Syntax : grep

Example : grep 99sk skpmcafile

   
 i
 
  


Answer:

Cat displays file contents. If the file is large the contents scroll off the screen before we view it.
So command 'more' is like a pager which displays the contents page by page.

  
    
9 

Answer:

Kill $!

   
 
  
   %
 2
   

Answer:

rm -r r

  
 %8 


   

Answer:

$od -cbd file_name


c - character, b - binary (octal), d-decimal, od=Octal Dump.

 i i
 
 

Answer:

$ echo r
It is similar to 'ls' command and displays all the files in the current directory.

Is it possible to create new a file system in UNIX?

Yes, µmkfs¶ is used to create a new file system.

     





Answer:
Yes, using the µmesg¶ command.

     


:2   !;2<":

Answer:
ls stands for list; so it displays the list of the files that starts with 'chapter' with suffix '1' to '5',
chapter1, chapter2, and so on.

7 8 


)i   

Answer:

Yes, it stands for µdisk usage¶. With the help of this command you can find the disk capacity and
free space of the disk.

   



    )

=)i 

Answer:

Yes, wc-stands for word count.


wc -c for counting number of characters in a file.
wc -l for counting lines in a file.

>    




 
 

Answer:

µinode¶, each file has a separate inode and a unique inode number.

i
%    
0>?%

Answer:

Two prompts, PS1 (Primary Prompt), PS2 (Secondary Prompt).

i 
 
 
 
 %

Answer:

Kernel checks 'type' field in the file's inode structure.

ii      


 

Answer:

Use µsu¶ command. The system asks for password and when valid entry is made the user gains
super user (admin) privileges.

     

Answer:

Shell variables are special variables, a name-value pair created and maintained by the shell.
Example: PATH, HOME, MAIL and TERM

    



Directing the flow of data to the file or from the file for input or output.
Example : ls > wc

i 
  i  



   %
 
@ 

With the help of kill command we can terminate the process.

Syntax: kill pid

Kill 0 - kills all processes in your system except the login shell.

   

 

A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the
output of the preceding command to be passed as input to the following command.

Example : ls -l | pr

The output for a command ls is the standard input of pr.

When a sequence of commands are combined using pipe, then it is called pipeline.

4 
*+
   
 '

There are four possible results from this call:


µkill()¶ returns 0. This implies that a process exists with the given PID, and the system would allow
you to send signals to it. It is system-dependent whether the process could be a zombie.

µkill()¶ returns -1, µerrno == ESRCH¶ either no process exists with the given PID, or security
enhancements are causing the system to deny its existence. (On some systems, the process
could be a zombie.)

  

 i    
 i 
 @%'

find / -type f -atime -30 > December.files


This command will find all the files under root, which is µ/¶, with file type is file. µ -atime -30ƍ will give
all the files accessed less than 30 days ago. And the output will put into a file call December.files.

     i%

  
A: The most graceful way is to use the command init s.
If you want to shut everything down before going to single user mode then do init 0 first and from
the ok prompt do a boot -s.

¬ 
   
 ?
All devices are represented by files called special files that are located in/dev directory. Thus,
device files and other files are named and accessed in the same way. A 'regular file' is just an
ordinary data file in the disk. A 'block special file' represents a device with characteristics similar
to a disk (data transfer in terms of blocks). A 'character special file' represents a device with
characteristics similar to a keyboard (data transfer is by stream of bits in sequential order).
2. What is 'inode'?
All UNIX files have its description stored in a structure called 'inode'. The inode contains info
about the file-size, its location, time of last access, time of last modification, permission and so
on. Directories are also represented as files and have an associated inode. In addition to
descriptions about the file, the inode contains pointers to the data blocks of the file. If the file is
large, inode has indirect pointer to a block of pointers to additional data blocks (this further
aggregates for larger files). A block is typically 8k.
Inode consists of the following fields:
O File owner identifier
O File type
O File access permissions
O File access times
O Number of links
O File size
O Location of the file data
O 'A       %  


0>?
O A Unix directory is a file containing a correspondence between filenames and inodes. A
directory is a special file that the kernel maintains. Only kernel modifies directories, but
processes can read directories. The contents of a directory are a list of filename and
inode number pairs. When new directories are created, kernel makes two entries named
'.' (refers to the directory itself) and '..' (refers to parent directory).
System call for creating directory is mkdir (pathname, mode).

   0
%  &B
O open(pathname,flag,mode) - open file
O creat(pathname,mode) - create file
O close(filedes) - close an open file
O read(filedes,buffer,bytes) - read data from an open file
O write(filedes,buffer,bytes) - write data to an open file
O lseek(filedes,offset,from) - position an open file
O dup(filedes) - duplicate an existing file descriptor
O dup2(oldfd,newfd) - duplicate to a desired file descriptor
O fcntl(filedes,cmd,arg) - change properties of an open file
O ioctl(filedes,request,arg) - change the behaviour of an open file
The difference between fcntl anf ioctl is that the former is intended for any open file, while the
latter is for device-specific operations.

i%  
3C . 

Every file has following attributes:
owner's user ID ( 16 bit integer )
owner's group ID ( 16 bit integer )
File access mode word
'r w x -r w x- r w x'

(user permission-group permission-others permission)


r-read, w-write, x-execute
To change the access mode, we use chmod(filename,mode).
Example 1:
To change mode of myfile to 'rw-rw-r±' (ie. read, write permission for user - read,write permission
for group - only read permission for others) we give the args as:
chmod(myfile,0664) .
Each operation is represented by discrete values
'r' is 4
'w' is 2
'x' is 1

Therefore, for 'rw' the value is 6(4+2).


Example 2:
To change mode of myfile to 'rwxr±r±' we give the args as:
chmod(myfile,0744).

  

%  

0>?% 
A link is a second name (not a file) for a file. Links can be used to assign more than one name to
a file, but cannot be used to assign a directory more than one name or link filenames on different
computers.
Symbolic link 'is' a file that only contains the name of another file.Operation on the symbolic link
is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links.
Commands for linking files are:
Link ln filename1 filename2
Symbolic link ln -s filename1 filename2
 33B
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said
to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can
be read only in the order written. It is used in interprocess communication where a process writes
to one end of the pipe (producer) and the other reads from the other end (consumer).

i%    


  
 

The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number
is the disk.


-  



% 
The privileged mount system call is used to attach a file system to a directory of another file
system; the unmount system call detaches a file system. When you mount another file system on
to your directory, you are essentially splicing one directory tree onto a branch in another directory
tree. The first argument to mount call is the mount point, that is , a directory in the current file
naming system. The second argument is the file system to mount to that point. When you insert a
cdrom to your unix system's drive, the file system in the cdrom automatically mounts to
/dev/cdrom in your system.

i 
    
Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks
in the file. The 11th address points to a one-level index block. The 12th address points to a two-
level (double in-direction) index block. The 13th address points to a three-level(triple in-
direction)index block. This provides a very large maximum file size with efficient access to large
files, but also small files are accessed directly in one disk read.

  
A shell is an interactive user interface to an operating system services that allows an user to
enter commands as character strings or through a graphical user interface. The shell converts
them to system calls to the OS or forks off a process to execute the command. System call
results and other information from the OS are presented to the user through an interactive
interface. Commonly used shells are sh,csh,ks etc.

A    


  D 
i  %  '
While booting, special process called the 'swapper' or 'scheduler' is created with Process-ID 0.
The swapper manages memory allocation for processes and influences CPU allocation. The
swapper inturn creates 3 children:

O the process dispatcher,


O vhand and
O dbflush
with IDs 1,2 and 3 respectively.
This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. Unix keeps
track of all the processes in an internal data structure called the Process Table (listing command
is ps -el).

    - i   


Unix identifies each process with a unique integer called ProcessID. The process that executes
the request for creation of a process is called the 'parent process' whose PID is 'Parent Process
ID'. Every process is associated with a particular user called the 'owner' who has privileges over
the process. The identification for the user is 'UserID'. Owner is the user who executes the
process. Process also has 'Effective User ID' which determines the access privileges for
accessing resources like files.

O getpid() -process id
O getppid() -parent process id
O getuid() -user id
O geteuid() -effective user id
4 
 *+% '
The `fork()' used to create a new process from an existing process. The new process is called
the child process, and the existing process is called the parent. We can tell which is which by
checking the return value from `fork()'. The parent gets the child's pid returned to him, but the
child gets 0 returned to him.

.      i


    
main()
{
fork();
printf("Hello World!");
}

Answer:
Hello World!Hello World!

Explanation:
The fork creates a child that is a duplicate of the parent process. The child begins from the
fork().All the statements after the call to fork() will be executed twice.(once by the parent process
and other by child). The statement before fork() is executed only by the parent process.

;'.       i
    
main()
{
fork(); fork(); fork();
printf("Hello World!");
}

Answer:
"Hello World" will be printed 8 times.
Explanation:
2^n times where n is the number of calls to fork()

;E'# %     

F
System calls Description

O fork() To create a new process


O exec() To execute a new program in a process
O wait() To wait until a created process completes its execution
O exit() To exit from a process execution
O getpid() To get a process identifier of the current process
O getppid() To get parent process identifier
O nice() To bias the existing priority of a process
O brk() To increase/decrease the data segment size of a process.
18. How can you get/set an environment variable from a program?
Getting the value of an environment variable is done by using `getenv()'. Setting the value of an
environment variable is done by using `putenv()'.

;G'i 
  

    
 
A parent and child can communicate through any of the normal inter-process communication
schemes (pipes, sockets, message queues, shared memory), but also have some special ways
to communicate that take advantage of their relationship as a parent and child. One of the most
obvious is that the parent can get the exit status of the chil d.

@' , 


When a program forks and the child finishes before the parent, the kernel still keeps some of its
information about the child in case the parent might need it - for example, the parent may need to
check the child's exit status. To be able to get this information, the parent calls `wait()'; In the
interval between the child terminating and the parent calling `wait()', the child is said to be a
`zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)

;'     


0

As a process executes it changes state according to its circumstances. Unix processes have the
following states:
Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.

Backing Up MySQL Database

MySQL database backup can be accomplished in two ways:

a) Copying the raw mysql database files &


b) Exporting tables to text files

/ %
 H%(# 

MySQL uses the same table format on different platforms, so it's possible to copy MySQL table and
index files from one platform and use them on another without any difficulties (assuming, of course,
that you're using the same version of MySQL on both platforms).
4  
 

The MySQLDump is handy utility that can be used to quickly backup the MySQL Database to the text
files. To use the MySQLDump utility it is required to logon to the System running the MySQL Databse.
You can use Telnet to remotely logon to the system if you don't have the physical access to the
machine.

The syntax for the command is as follows.

mysqldump -u Ô  -pÔ 


  Ô  > [ 
[username] - this is your database username
[password]- this is the password for your database
[databasename] - the name of your database
[backupfile.sql] - the filename for your database backup

Let's discuss the example of backing up MySQL Database named "accounts" into text file
accounts.sql. Here are the scenarios of taking the backup assuming that both user name and
password of the database is "admin".

a) Taking the full backup of all the tables including the data.
Use the following command to accomplish this:
mysqldump -u admin -p admin accounts > accounts.sql

b) Taking the backup of table structures only.


Use the following command to accomplish this:
mysqldump -u admin -p admin --no-data accounts > accounts.sql

c) Taking the backup data only.


Use the following command to accomplish this:
mysqldump -u admin -p admin --no-create-info accounts > accounts.sql

Restoring MySQL Database

Restoring the MySQL is very easy job. You can use the following to command to restore the accounts
database from accounts.sql backup file.

%D2 
2 
 
I 
'D

In this tutorial you learned how to take the backup of your MySQL Database and restore the same in
the event of some database crash or on some other machine.

You might also like