Complete.Org: Mailing Lists: Archives: discussion: October 2001:
[aclug-L] FW: Executing job controls from a command shell

[aclug-L] FW: Executing job controls from a command shell

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Aclug Discussion" <discussion@xxxxxxxxx>
Subject: [aclug-L] FW: Executing job controls from a command shell
From: "Dale W Hodge" <dwh@xxxxxxxxxxxxxxxx>
Date: Fri, 5 Oct 2001 09:34:23 -0500
Reply-to: discussion@xxxxxxxxx

LINUX TIPS AND TRICKS --- October 05, 2001
Published by -- changing the way you view IT


* Danny runs through some simple commands that will allow you to take
  command of the jobs running on your system.

Job Control
By Danny Kalev

To distinguish them from system processes, the commands that users
execute from a shell or a script file are often called "jobs". This
week, I will show you how a set of job control operations can allow the
user to control the execution of such jobs from the command shell.

Background Execution
Placing an ampersand at the end of the command executes a job in the
background. The system assigns each user's job a unique number in
addition to a PID. When you execute a command in the background, a
user's job number and a system process id appear on the screen. For

    $ lpr payroll &
    [1]   236

The number in brackets is the user's job id; the second number is the
system process's PID. You can place multiple commands in the background
at once by separating each command with an ampersand. For example:

    $ lpr july & cat *.c &

The "jobs" command lists the current background jobs. Jobs displays
each entries' job number in brackets, whether it's stopped or running,
and its name:

    $ jobs
    [1]   +   Running   lpr july
    [2]   -   Running   cat *.c

A plus sign indicates that the job is currently being processed. A
minus sign indicates the next job to be executed.

By default, Linux doesn't interrupt other operations, say an editing
session, to notify you that a certain job has completed. If you wish to
be notified on a job's completion, then use the "notify" command.
Notify takes a job number preceded by a percent sign as its argument:

    $ notify %2

This will cause the system to notify you when job 2 has completed,
regardless of your current activity.

Switching between Background and Foreground
You can bring a background job to the foreground by executing the "fg"
command. If there are several background jobs, then you must indicate
which job you wish to move to the foreground by indicating its job

    $ fg %2

Likewise, you can move a currently running foreground job to the
background with the "bg" command. In order to do that, you first need
to suspend the job by pressing CTRL-Z. Then issue the bg command to
resume the suspended job's execution in the background. For example:

    $ lpr july
    $ bg

Killing a Job
To cancel a running job, use the "kill" command. kill takes a PID or a
job number preceded by % as its argument. In the following example, the
user examines the currently running jobs and cancels job 2:

    $ jobs
    [1]   +   Running   lpr july
    [2]   -   Running   cat *.c
    $ kill %2


About the author(s)
Danny Kalev is a system analyst and software engineer with more than 10
years of experience, specializing in C++ and object-oriented analysis
and design on various platforms including VMS, DOS, Windows, Unix, and
Linux. His technical interests involve code optimization, networking,
and distributed computing. He is also a member of the ANSI C++
standardization committee and the author of ANSI/ISO C++ Professional
Programmer's Handbook (Que, 1999). Danny can be reached at


Configuring Job Controls

PID Control Technical Notes

What Is PID - Tutorial Overview


Index of Linux Tips and Tricks

Writing to syslog

Introducing Firewalls


- Go to:
- Click on "View my newsletters" to log in and manage your account
- To subscribe, check the box next to the newsletter
- To unsubscribe, uncheck the box next to the newsletter
- When finished, click submit

Questions? Please e-mail customer service at: mailto:support@xxxxxxxxxxx


* Editorial: Andrew Santosusso, Newsletter Editor,
* Advertising: Clare O'Brien, Vice President of Sales,
* Recruitment advertising: Jamie Swartz, Eastern, Regional Sales
  Manager, jamie_swartz@xxxxxxxxxxx or Paul Duthie, Western Regional
  Sales Manager, paul_duthie@xxxxxxxxxxxxx
* Other inquiries: Jodie Naze, Senior Product Marketing Manager,


Copyright 2001, Inc., All Rights Reserved.

-- This is the discussion@xxxxxxxxx list.  To unsubscribe,

[Prev in Thread] Current Thread [Next in Thread]
  • [aclug-L] FW: Executing job controls from a command shell, Dale W Hodge <=