LiveFire Labs - Online UNIX Training - Company Logo


Online UNIX Training with Hands-on Internet Lab


"Eliminate the expense and inconvenience of classroom training without eliminating the classroom experience."

 


Home
Internet Lab
Console Access
Sample Course

Student Login


LiveFire Labs' UNIX Tip, Trick, or Shell Script of the Week - View


Questions? Call
1.888.843.1637 or send us email





Co-processes - Part I - Review of Foreground and Background Jobs

When tackling a relatively advanced topic such as co-processes, a review of foreground and background jobs is a good place to begin.

Each time you run a command or program on the system, you are running a job. A job consists of one or more processes working to perform a specific task.

By default, a job is started in what is called the foreground. This means that you have to wait until the job has completed prior to running another command or program (the command prompt will not be displayed until a foreground job has completed). If you are running commands or programs that take a long time to finish, this can be an unacceptable situation. To avoid this you have the option of running a job in what is call the background.

The background allows you to start a job detached from the foreground so that you can work on other tasks or start additional jobs. When a job is started in the background, the command prompt is returned to you immediately. To start a job in the background, an & (ampersand) character is appended to the end of the command line:

$ ./loop10 &
[1] 12420
$

This command starts a job running the program loop10 in the background, and then displays the command prompt.  The 1 in the brackets is the job number, and 12420 is the PID.

The program loop10 is a simple program that loops 10 times and then exits:

$ cat loop10
#! /bin/ksh

i=1
while [ $i -le 10 ]
do
   echo "" > /dev/null
   sleep 1
   (( i=i+1 ))
done

exit 0
$
Once the program exits, the following informational message is displayed to standard output:

$
[1] + Done ./loop10
$




Learn more...
  

If you are new to the UNIX or Linux operating system and would like to learn more, you may want to consider registering for LiveFire Labs' UNIX and Linux Operating System Fundamentals online training course.

If you already have a solid grasp of the fundamentals but would like to learn more about the Korn shell and basic and advanced shell scripting, taking our Korn Shell Scripting course will be beneficial to you.

Our innovative hands-on training model allows you to learn UNIX by completing hands-on exercises on real servers in our Internet Lab.


More Tips...

· 
Popular UNIX Tips from the Past

spacer Box Border
 

Receive the UNIX Tip, Trick, or Shell Script of the Week by Email


First Name:


Email Address:






   1.888.843.1637

Home - Contact us - Company info - Privacy Statement   

 
©2002-2004 LiveFire Labs.  All rights reserved.
Linux® is a registered trademark of Linus Torvalds, author and developer of this public domain operating system.
UNIX® is a registered trademark of The Open Group in the United States and other countries.