Running several processes simultaneously, Running foreground processes, Running background processes – HP NonStop G-Series User Manual

Page 138

Advertising
background image

the shell to write the standard error output (file descriptor 2) to the file associated with the standard
output file (>&1), outfile.

Running Several Processes Simultaneously

Open System Services can run a number of different processes at the same time. To make optimum
use of this capability, you’ll want to execute some commands as foreground processes and others
as background processes.

Running Foreground Processes

Normally, when you enter a command on the command line, you wait for the results to display on
your screen. Commands entered one at a time at the shell prompt are called “foreground processes.”
After executing one command as a foreground process, you cannot execute another until the first
one has finished.

Commands that take only a few seconds to finish are fine to run as foreground processes. However,
commands that take longer are often best run as background processes to free the command line
for new commands.

Running Background Processes

To run a command as a background process, you end the command with an & (ampersand):

$ find options filename &

After a process is running in the background, you can perform additional tasks by entering other
commands on the command line. (See

Chapter 12 (page 147)

for more information about the find

command.)

After you create a background process, the following takes place:
1.

The OSS process identification number is displayed. Open System Services creates and assigns
process IDs and job numbers so that all processes currently running on the system can be
tracked.

2.

The prompt returns so that you can enter another command.

When you create a background process, note its process ID. The process ID helps you to monitor
or terminate the process. See

“Monitoring and Canceling Processes” (page 139)

for more information.

Because background processes increase the amount of work the system must do, background
processes may slow down other processes. This can be a problem, depending upon how much
the system slows and the nature of the other work you do while background processes run.

Most processes direct their output to the standard output file, even when they run in the background.
Because the output from a background process can interfere with your other work, it is usually
good practice to redirect the output of a background process to a file or to a printer. Then you
can look at the output whenever you are ready. For more information about redirecting output,
see the examples later in this chapter, as well as

“Redirecting Input and Output” (page 135)

.

The examples in the rest of this subsection use the find command, which takes more than a few
seconds to run:

find / -type f -print

This command displays the pathnames for all files on your system. You do not need to study the
find

command to complete this subsection—it is used here simply to demonstrate how to work

with processes. If you want to learn more about the find command, see

“Finding Files (find)”

(page 149)

and the find(1) reference page either online or in the Open System Services Shell

and Utilities Reference Manual.

In the following example, the find command runs in the background (&) and redirects its output
to a file named dirpaths (with the > symbol):

138

Managing Processes

Advertising
This manual is related to the following products: