Investigating & Managing Process :

What is a process:
A process is an instance of a running program. It is the job of Kernel to manage CPU time and other resources among multiple processes.
Each process is given a unique PID (process ID). PID is allotted by Kernel when a process is born.

Listing Process:

# ps   (displays the following)

PID

TTY

TIME

CMD

22794

tty1

00:00:00

bash

22809

tty1

00:00:00

ps


Finding Process:

# ps  axu  | grep tty2
(shows all process, running on all terminal by all users. Use grep for filtering)

# ps -eaf | grep sshd

 

# pgrep  -u  username      
(to see PID related to specific user)

 

#pidof  crond                    
(to see PID of specific process)

 

Signals: Signals are messages that are sent to processes with a command like kill.
The advantage of signals is that they can be sent to a process even if it is not attached to a terminal. So if a web server or a graphical program whose interface has “frozen” can still be shut down by sending appropriate signal.

 

Sending signals to processes:

  • Process normally terminate on their own when they have completed.
  • Interactive application may need the user to issue a quit command.
  • CTRL + C also terminate the process, which send an interrupt (INT) signal to a process.
  • If a process doesn’t terminate using above method, you can use KILL signal.
    (Remember it should only be used when the above method doesn’t work. Using KILL signal on a routine basis may cause zombie process and loose data)


5. Scheduling Priority:

  • Every running process has a scheduling priority, Whoever has got higher priority, gets more attention of the CPU.
  • The priority of process is set by altering niceness value.
  • The niceness value defaults to zero(0) but can be set from -20 (least value, highest piority) to 19 (highest value, least priority)


Note:
Non-privileged users can not set niceness value lower than 0, it means they can't set their processes to get higher priority.

To set the niceness value to a specific value when starting a process, use nice  -n as following:

nice -n  13  vim  file.txt     (to run vim at 13 niceness value)
nice -n  -13  vim  file.txt    (to run vim at -13 niceness value)

To modify the niceness value of running processes, use renice command as following:

renice   15   PID                 (Where PID is process ID of running process)
renice   -15  PID

Note:
Non-privileged users can not set niceness value lower than 0, it means they can't set their processes to get higher priority.

Interactive Process Management Tools:

Running top presents a list of the processes running on your system, updated every 5 seconds, you can use keystrokes to kill, renice, colorize processes, define the order to display etc. Press the ? key while in top to view the complete list of hotkeys.

Job Control:

Jobs running in the foreground can be suspended: temporarily stopped, without being killed. To suspend a job, Press Ctrl + z. Once a process is suspended, it can be resume in the background using the bg command or resumed in the foreground using the fg command. When the job resumes, it will continue executing from the point at which it was suspended. It will not have to start over from the beginning.

# man mkdir  (press ctrl + z to suspend this job)
[1]+ stopped

bg

to resume the recent suspended job in background

bg 2

to resume the job 2 in background

jobs

to see all suspended job

fg  2

to resume the job 2 in foreground


Note
:

  • The plus or minus sign next to the jobs number tells which job is default, i.e. the jobs that is referenced if no job number is given when running bg or fg command (You can say + shows last job, - shows second last job)
  • To run a command in background, just add & at the end of command line and press Enter to run that command in background.
  • # (command1;command2)& (to run both command in background)

 

# sort  list1 > sorted-list1

Connect With Us
Instant Query
Your Name :
Email Address :
Message :