Pages

Monday, 1 September 2014

Process & Memory

Command Description
ps Displays the list of process submitted to kernel
pstree Displays the process in the form of tree diagram
bg Displays the status of process running in background
fg Used to bring any background job in foreground
nice Execute a command with updated scheduling priority
kill Used to send signal to perticular process
nohup Execute the command in background even after user get log out
df Print the system disk space usage and available
du Estimate file space usage in current directory

                Process related command
ps command
To see the list of processes submitted to kernel
Syntax
$ ps [option..]

To see full listing with PPID and including user and system process.
$ ps -ef

where :
-e to display all the processes.
-f to display full format listing.

To see every process with PPD and user on the system using BSD syntax:
$ ps -awx (or)  ps awx

where :
-a,a  all w/ tty, including other users
-w,w  wide output
-x,x  processes w/o controlling ttys

pstree command
To see the process in the form of tree diagram.
Syntax :
$ pstree [options] [pid or username]

To see the tree diagram with process identification numbers (PIDs)
$ pstree -p

We can use more or less command along with pstree to see pagewise view
$ pstree | less (or)  pstree | more

To see only those branches that have been initiated by a user with a username mukesh
$ pstree mukesh

bg command 
It can be used to see the status of jobs which are running in the background.
$ bg

fg command
To bring the job in foreground from background by its JobId or PID
Syntax
$ fg %JobID (or)  fg #PID

Some examples on background and foreground processes:
Below command will execute the process created by the shell in foreground and the output is redirecting in file1.
$ ls -laFrR > file1

To send the above process in the background add one symbol '&' at the end of command.
$ ls -laFrR > file1 &

[1] 3951

The value 1 written in square bracket is JobID for this job and 3951 is PID for this process.

Immediate after running above command we can check the status of this background processes.
$ bg

bash: bg: job 1 already in background

Once this background process get over , the status will be like below
$ bg

bash: bg: current: no such job

To bring this job in foreground, use the following command
$ fg %1      (or)      fg #3951

nice command
Use nice command to run a program with modified scheduling priority
Nicenesses range at least from -20 (resulting in the most favorable scheduling) through 19 (the least favorable). The default behavior is to increase the
niceness by 10.
Syntax
$ nice [option][command]

Examples on nice command
To see the current scheduling inherited priority
$ nice

Below command will execute ls command with incremented scheduling priority. Here we are not giving any adjustment to priority, so by default priority
is incremented by 10.
$ nice  ls

To increase the scheduling priority by 5
$ nice –n5 ls

kill command
Kill sends signal to the process having with process ID as pid. If no option is specified,it sends default signal 15 (software termination signal) to the process.
Syntax
$ kill [signal] PID

Where :
Option - 1   Hang-up signal.
Option - 2   Interrupt signal.
Option - 9   terminate the process.
Option -15   Software termination signal.

Example: 
$ kill  -9  3951

Rules on the kill command
1.You can kill all your own process.
2.Only root user can kill system level process.
3.Only root user can kill process started by other users.

nohup command
nohup command allows to run command/process or shell script that can continue running in the background after you log out from a shell
Syntax:
$ nohup <commandname/shells-script>
(or)
$ nohup <commandname/shells-script> &

Example: 
$ nohup txncleanup.sh  &

Memory related command
df command
Report the amount of disk space being used by file systems,If no file name is given, the space available on all currently mounted file systems is shown.
Syntax
$ df [option] [file_name]

Type the below command to see variaous option which can be used along with df
$ df --help

Example :
To display all file systems and their disk usage
$ df

output:
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            150900956  94750776  48484824  67% /
none                    504780       280    504500   1% /dev
none                    509024      2164    506860   1% /dev/shm
none                    509024       208    508816   1% /var/run
none                    509024         0    509024   0% /var/lock
none                    509024         0    509024   0% /lib/init/rw

To display above command in human readable format
$ df -h

output:
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             144G   91G   47G  67% /
none                  493M  280K  493M   1% /dev
none                  498M  2.1M  495M   1% /dev/shm
none                  498M  208K  497M   1% /var/run
none                  498M     0  498M   0% /var/lock
none                  498M     0  498M   0% /lib/init/rw

du command
du estimates and displays the disk space used by files.
Summarize disk usage of each FILE, recursively for directories.
Syntax
$ du [option] [filename]

$ du [option] --files0-from=F

Example
To display the size of each files starting from 'f' in current directory.
$ du -sh f*

Type the below command to see variaous option which can be used along with du
$ du --help


No comments:

Post a Comment