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

[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 ITworld.com -- changing the way you view IT
http://www.itworld.com/newsletters
____________________________________________________________________________
____

HIGHLIGHTS

* 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
example:

    $ 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.

Notification
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
number:

    $ 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
    ^Z
    $ 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
linuxnl@xxxxxxxxxx.
____________________________________________________________________________
____

ADDITIONAL RESOURCES

Configuring Job Controls
http://itw.itworld.com/GoNow/a14724a43301a76028222a0

PID Control Technical Notes
http://itw.itworld.com/GoNow/a14724a43301a76028222a2

What Is PID - Tutorial Overview
http://itw.itworld.com/GoNow/a14724a43301a76028222a3
____________________________________________________________________________
____

ITWORLD.COM NEWSLETTER ARCHIVE

Index of Linux Tips and Tricks
http://www.itworld.com/nl/lnx_tip/

Writing to syslog
http://www.itworld.com/nl/lnx_tip/11032000/

Introducing Firewalls
http://www.itworld.com/nl/lnx_tip/11172000/
____________________________________________________________________________
____

CUSTOMER SERVICE

SUBSCRIBE/UNSUBSCRIBE:
- Go to: http://www.itworld.com/newsletters
- 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
____________________________________________________________________________
____

CONTACTS

* Editorial: Andrew Santosusso, Newsletter Editor,
  andrew_santosusso@xxxxxxxxxxx
* Advertising: Clare O'Brien, Vice President of Sales,
  clare_obrien@xxxxxxxxxxx
* 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,
  jodie_naze@xxxxxxxxxxx
____________________________________________________________________________
____

PRIVACY POLICY

http://www.itworld.com/Privacy/

Copyright 2001 ITworld.com, Inc., All Rights Reserved.
http://www.itworld.com



-- This is the discussion@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


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