February 19, 2007

Zombie Process

Zombie process is an inactive computer process, according to wikipedia article, "…On Unix operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. In the term's colorful metaphor, the child process has died but has not yet been reaped…"

So how do I find out zombie process?

Use top or ps command:
# top
OR
# ps aux awk '{ print $8 " " $2 }' grep -w Z

Output:

Z 4104

Z 5320

Z 2945

How do I kill zombie process?

You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

You can kill zombie process using PID obtained from any one of the above command। For example kill zombie proces having PID 4104:


# kill -9 4104

Please note that kill -9 does not guarantee to kill a zombie process (see below for more info).

What are these zombie processes that show up in ps? I kill them but they don't go away!

Zombies are dead processes. You cannot kill the dead. All processes eventually die, and when they do they become zombies. They consume almost no resources, which is to be expected because they are dead! The reason for zombies is so the zombie's parent (process) can retrieve the zombie's exit status and resource usage statistics. The parent signals the operating system that it no longer needs the zombie by using one of the wait() system calls.

When a process dies, its child processes all become children of process number 1, which is the init process. Init is ``always'' waiting for children to die, so that they don't remain as zombies.

If you have zombie processes it means those zombies have not been waited for by their parent (look at PPID displayed by ps -l). You have three choices: Fix the parent process (make it wait); kill the parent; or live with it. Remember that living with it is not so hard because zombies take up little more than one extra line in the output of ps.

February 10, 2007

Automating the FTP Process in Linux

#!/bin/sh
# Automating the FTP Process

clear
echo "Executing FTP Transfer"
echo "Please Enter Hostname"
read Host
echo "Please Enter Username"
read USER
echo "Please Enter Password"
read PASSWD
echo "Please Enter the Path"
read Path
echo "Please Enter the name of the File"
read Name

ftp -n $Host << SCRIPT
quote USER $USER
quote PASS $PASSWD
bi
cd $Path
get $Name
bye
SCRIPT
exit 0

February 1, 2007

Unix Interview Questions

split in unix

split [ -b n | nk | nm] [-a suffixlength] [ file [name]]

time zone in unix

1. To modify the time zone check the following files.....

cd "/usr/share/lib/zoneinfo"

2. It contains contains a list of all the Time-Zone that are available.

3. If "Asia" dir is present goto step 4.

4. zic asia

5. ls Asia

6. You should see "Calcutta" when you use the above command.

7. If you find "Calcutta" goto step 5 else send email to gong_ops.

8. Edit /etc/default/init file so that it contains TZ=Asia/Calcutta

9. Reboot the workstation.

10. Use the "date" command to set the workstation time to local time.

11. date

12. date -u // this gives you the UT time.

13. You should see a difference of 11/2 hours.


Details of ram capacity with unix command

Prtconf


Finding a file in the entire file system

whereis, where


Shutdown command in unix

Shutdown


Reboot command in unix

Reboot


kill -9 used for?

kill -9 100 -165

sends the SIGKILL signal to the process whose process ID is 100 and
to all processes whose process group ID is 165.

Mount a cdrom on a different system and get access

mount -r -Fhsfs /dev/device/cdrom


Various filesystems

ext2 default file system for many Linux distributions

ext3 ext2 + journaling, which means that no fsck is required after a power failure

reiserfs, xfs newer file systems, similar to ext2, but improve on various aspects
(journaling, speed, size, efficiency)

iso9660 used by most cdroms

proc special virtual file system, none of the files actually exist, but they are
created by the kernel on the fly, eg cat /proc/filesystems contains a list of
supported file system types on the current system

devfs virtual file system for devices (see below)

msdos dos file system, with 8.3 file names only

vfat win95, 98, 2K, XP file system, supports long file names

ntfs read-only support for NTFS (as used by NT, 2K, XP)

os


what is Zombie process?

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.)


how do you prioritize a process?

with nice command

Run Levels in Linux

The Linux OS like Windows runs "services." There are times when you may want some or all installed services to run. This is where "runlevels" are used. Runlevels are used to specify different configurations of running services. The chart below shows a basic outline of the standard init levels.

Init Level

Comments

0

Runlevel 0 is reserved for the "shutdown" phase. Entering init 0 from the shell prompt will shutdown the system and usually power off the machine.

1

Runlevel 1 is usually for very basic commands. This is the equivalent to "safe mode" used by Windows. This level is usually only used to asses repairs or maintenance to the system. This is a single-user mode and does not allow other users to login to the machine.

2

Runlevel 2 is used to start most of the machines services. However, it does not start the network file sharing service (SMB, NFS). This will allows multiple users to login to the machine.

3

Runlevel 3 is commonly used by servers. This loads all services except the X windows system. This means the system will boot to the equivalent of DOS. No GUIs (KDE, Gnome) will start. This level allows multiple users to login to the machine.

4

Runlevel 4 is usually a "custom" level. By default it will start a few more services than level 3. This level is usually only used under special circumstances.

5

Runlevel 5 is everything! This will start any GUIs, extra services for printing, and 3rd party services. Full multi-users support also. This runlevel is generally used on by workstations.

6

Runlevel 6 is reserved for "reboot" only. Be carefully when running this command. Once you have entered init 6, there is no stopping it!

What is Running and When?

There will be a time when you want to know what services are running, and the different runlevels they are specified in. You can use a simple command to display a list of all runlevels and services used by them. The text below shows the output of the chkconfig --list command.

[root@roswell root]# chkconfig --list
microcode_ctl   0:off   1:off   2:on    3:on    4:on    5:on    6:off
gpm             0:off   1:off   2:on    3:on    4:on    5:on    6:off
kudzu           0:off   1:off   2:off   3:off   4:on    5:off   6:off
syslog          0:off   1:off   2:on    3:on    4:on    5:on    6:off
daytime:     off
echo-udp:    off
echo:        off
services:    off
time:        off
time-udp:    off
cups-lpd:    off
sgi_fam:     on
tftp:        off
ktalk:       off
swat:        on



Notice that each services is followed by columns for each of the 6 runlevels. Now of course there will also be a time when you need to make changes to a specific runlevel. Using the output from above, let's say we want to turn on lisa for runlevel 5. You can do this using the command shown below:

[root@roswell root]# chkconfig --level 5 lisa on
[root@roswell root]# 

If no errors are reported, you must have correctly entered the syntax of the this command. Notice that you must have 2 - signs before level. The opposite is also true. Let's now say that we don't want lisa to start everytime we boot the machine to init 5. You can turn that service off by entering the reciprocal of the previous command show below:

[root@roswell root]# chkconfig --level 5 lisa off
[root@roswell root]# 



More info is also available about runlevels from the manual pages. You can view the man pages by using the command:

[root@roswell root]# man init
[root@roswell root]# 
 
INIT(8)               Linux System Administrators Manual              INIT(8)
 
NAME
       init, telinit - process control initialization
 
SYNOPSIS
       /sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
       /sbin/telinit [ -t sec ] [ 0123456sSQqabcUu ]
 
DESCRIPTION
  Init
       Init  is  the  parent  of all processes.  Its primary role is to create
       processes from a script stored in  the  file  /etc/inittab  (see  init-
       tab(5)).   This file usually has entries which cause init to spawn get-
       tys on each line that users can log in.  It  also  controls  autonomous
       processes required by any particular system.
 
RUNLEVELS
       A  runlevel is a software configuration of the system which allows only
       a selected group of processes to exist.  The processes spawned by  init



I truncated the rest of the manual entry above. Using runlevels is must for every Linux user. The init file configuration are stored in the /etc/inittab file. By editing this file, you can change the default runlevel upon boot up. The output below shows the inttab file:

[root@roswell root]# vi /etc/inittab
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, 
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
 
# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, 
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
 
# 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:
 
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
 
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
 
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
 
# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
 # If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
Notice the line above that I have highlighted in red:

id:3:initdefault:

This specifies the default runlevel for the system. This means that every time the system reboots; it will bring up init 3. You can easily change this to whatever runlevel you want. Just be sure not to change the numeric value to 0 or 6! The two most common values are 3 and 5.