Monday, November 21, 2011

UNIX Process or Jobs: Suspend and Resume

In unix whatever command you execute from the command line initiate a process. Say for example you tried ls tol list files invokes the process ls.  In UNIX any program that's running is a process. You can have multiple process running at once.

Any program that you are running is known as current job.

States of Jobs/Process:
There are different states for the Jobs/Process in UNIX. The most important one is "running".

Stopping and restarting a Job:
A job can be stopped by pressing ctrl+z and to restart it enter fg.

bash-3.00$ ./logging.sh
Stopping the server please wait .........\n
Tue Nov 22 12:08:52 IST 2011
Invoking the PL/SQL Procedures and Bulk add command \n
Bulk Add Start Time:
Tue Nov 22 12:08:52 IST 2011
^Z
[1]+  Stopped                 ./logging.sh
bash-3.00$ fg
./logging.sh
Bulk Add End Time:
Tue Nov 22 12:09:09 IST 2011
Done with  PL/SQL Procedures and Bulk add. Starting the server. Please wait....\n
Tue Nov 22 12:09:09 IST 2011
1
bash-3.00$
Why we use ctrl+z to stop and fg to restart it later?
These commands helps us to stop a a job or process (ctrl+z) that we are doing currently and perform some other job and then resume (fg) our stopped job later.

For example if we are working on a vi editor editing our file and in between you want to execute some other programme press ctrl+z and once after completing your second job you can resume to editing your file by entering fg.

bash-3.00$ vi
I am testing stopping job and resuming it later
let me stop the job now !!
i am pressing ctrl+z!!   ^Z^Z^Z^Z^Z^Z
ooops!! Before pressing ctrl+z we should be in command mode!!
Moving to command mode and then pressing ctrl+z

~
~
~
Incomplete shell escape command - use 'shell' to get a shell
[1]+  Stopped                 vi
bash-3.00$
bash-3.00$ ls -l | tail -5
-rw-r--r--   1 fwire    fwire       1331 Apr 20  2011 publishpreview.sh
-rw-r--r--   1 fwire    fwire         11 Feb 25  2011 publishpreview_dummy.sh
-rw-r--r--   1 fwire    fwire        275 Oct 15 17:28 shiyas_new.txt
-rw-r--r--   1 fwire    fwire       1622 Oct 15 16:35 test.sh
-rw-r--r--   1 fwire    fwire        313 Oct 15 17:15 uniqtest.txt
bash-3.00$fg
 I am testing stopping job and resuming it later
let me stop the job now !!
i am pressing ctrl+z!!   ^Z^Z^Z^Z^Z^Z
ooops!! Before pressing ctrl+z we should be in command mode!!
Moving to command mode and then pressing ctrl+z


I am back !!
~

No comments:

Post a Comment