Linux Process Management Basics

Linux OS Topics
Post Reply
Ageek
Sergeant
Sergeant
Posts: 22
Joined: Sat Aug 01, 2009 10:54 am

Linux Process Management Basics

Post by Ageek » Mon Jun 20, 2011 10:01 am

Linux Process Management

A process can be identified as a set of instructions loaded to the memory. Every process has UID and GID.

Who is the owner of the ‘firefox’ program?

Code: Select all

stat /usr/bin/firefox
	stat $(which firefox)

Observe,
Get PID, Executed User, Real User, Common Name

Code: Select all

ps axo pid,euser,ruser,comm |grep firefox
ps axo pid,euser,ruser,comm |egrep ‘init|firefox’
Get PID, %CPU, % MEM, Executed User, Real User, Common Name

Code: Select all

	ps axo pid,%cpu,%mem,tty,euser,ruser,comm |less

find the parent process

Code: Select all

pstree |less


What is a Signal in Linux

This a UNIX concept which is used to inter-process communication. Using Signal can send a message directly to a process. There are many Signal types are available. Most frequently use signal are;
HUP (1) -> re-read the config file
KILL (9) -> Terminate immediately
TERM (15) -> Terminate gracefully

Further, observe

Code: Select all

man 7 signal
Command use for sending Signals

Code: Select all

kill
killall
pkill
pgrep
Exersises:

Observe:

1.

Code: Select all

        $ pgrep crond
	$ pgrep cupsd

	# kill -HUP $(pgrep crond)
	# kill -HUP $(pgrep cupsd)

	$ pgrep crond	-> has PID got changed?
	$ pgrep cupsd  	-> has PID got changed?

	# kill -9 $(pgrep cupsd)
	$ pgrep cupsd

	# service crond start
	$ pgrep crond 	-> check the PID
2.

Code: Select all

        $ firefox &
	$ killall firefox		->Observe the firefox
	
	$ pkill firefox
3.

Code: Select all

$ firefox
	$ ctrl + z

	$ jobs 	-> find the job id
	$ bg %1	-> resume the background process 1
	
	$ fg %1	
	$ kill %1

Start Stop Services

All init script of the process are usually in /etc unless if you have given a installing prefix when compiling the packages.

How to use;

Code: Select all

/etc/init.d/servicename start|stop|reload|restart|status
OR

Code: Select all

service servicename start|stop|reload|restart|status

Start Stop service while Boot and Shutdown time

At the booting process kernel start the init process, which is the master process of the system. Then read the /etc/inittab to decide the default runlevel.

Observ:

Code: Select all

cat /etc/inittab
|
|
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (same as 3, do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault: # default runlevel
According to the runlevel defined the appropriate directory is used to run the initial script.

Code: Select all

				|- rc0.d
				|
				|- rc1.d
				|
				|- rc2.d
				|
	/etc/rc.d/|- rc3.d
				|	
				|- rc4.d
				|
				|- rc5.d
				|
				|- rc6.d


Observ:

Code: Select all

	ls -al /etc/rc.d/rc5.d

Code: Select all

K95cgconfig -> ../init.d/cgconfig
K95firstboot -> ../init.d/firstboot
S02lvm2-monitor -> ../init.d/lvm2-monitor
S07iscsid -> ../init.d/iscsid

Anatomy of the init scripts

Code: Select all

                     S 07 iscsid
S for start at boot _|	|	|_  init script			
K dont start		|_ prority level			

Create a script to start at the beginning will be discussed later on
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Linux Process Management Basics

Post by Neo » Mon Jun 20, 2011 11:53 am

This is extremely useful. Well done!
User avatar
Nipuna
Moderator
Moderator
Posts: 2729
Joined: Mon Jan 04, 2010 8:02 pm
Location: Deraniyagala,SRI LANKA

Re: Linux Process Management Basics

Post by Nipuna » Mon Jun 20, 2011 1:10 pm

I like Linux. :)
Post Reply

Return to “Linux”