tags:

views:

112

answers:

4

What is the difference between a job and a process in Unix ? Can you please give an example ?

+3  A: 

Jobs are processes which are started by a shell. The shell keeps track of these in a job table. The jobs command shows a list of active background processes. They get a jobspec number which is not the pid of the process. Commands like fg use the jobspec id.

In the spirit of Jürgen Hötzel's example:

find $HOME | sort &
[1] 15317
$ jobs
[1]+  Running                 find $HOME | sort &
$ fg
find $HOME | sort
  C-c C-z
[1]+  Stopped                 find $HOME | sort
$ bg 1
[1]+ find $HOME | sort &

Try the examples yourself and look at the man pages.

Eddy Pronk
can u pleasse explain with example in unix
+2  A: 

http://en.wikipedia.org/wiki/Job_control_%28Unix%29

Jobs are one or more processes that are grouped together as a 'job', where job is a UNIX shell concept.

Will
can u pleasse explain with example
+5  A: 

http://en.wikipedia.org/wiki/Job_control_%28Unix%29:

Processes under the influence of a job control facility are referred to as jobs.

Carsten
+1  A: 

A Process Group can be considered as a Job. For example you create a background process group in shell:

$ find $HOME|sort &
[1] 2668

And you can see two processes as members of the new process group:

$ ps -p 2668 -o cmd,pgrp 
CMD                          PGRP
sort                         2667


$ ps -p "$(pgrep -d , -g 2667)" -o cmd,pgrp
CMD                          PGRP
find /home/juergen           2667
sort                         2667

You can can also kill the whole process group/job:

$ pkill -g 2667
Jürgen Hötzel
Thanks, I learned a few things here.
Eddy Pronk