CST8177 - Lab #6

Student Name:

Student Number:

Lab section:




Process Management

Objectives

Lab Outcome

In-Lab Demo: List the steps required to submit a weekly system job.

Section A - Process management

In order to manage processes on a system, you need to be able to both view and access those processes. Commands to do so include:

Process management commands

ps

to list existing processes on the local system

jobs

to list existing background jobs

fg and bg

to move jobs between the background and foreground

kill

to send a signal to a process using the PID or job number

killall

to send a signal to all processes using the process name

Ctrl-C

to kill a process currently running in the foreground (also ^C)

top

to view currently running processes and the resources associated to them (use q to quit, h for help)

pgrep

look up processes, based on the name or on other attributes

pstree

to display process relationships (hierarchy)

Resource management commands

free

to generate information about how much free memory is available on the system

vmstat

reports information about processes, memory, paging, block IO, traps, and cpu activity.

Try a variety of the commands in the questions below to locate the best one for accomplishing the tasks requested.

Exercise #1: Using process management utilities

Using the utilities above, or other suitable commands, answer the questions below:

Exercise #2: Working with job control

Job control commands

jobs

to list current processes started by this particular shell

CTRL-Z or ^Z

to stop execution of a process running in the foreground

bg %jobnum

to move a suspended job into the background

fg %jobnum

to move a background job to the foreground

kill %jobnum

to terminate a background job

At terminal #1

At terminal #2

At terminal #1


Section B - Job Scheduling

In this section, you create and modify crontab entries to observe how the normal scheduling system works. You will find some good information about the format and content of the crontab in man 5 crontab., and information about the crontab command in man 1 crontab (yes, they are different). Be sure to check anacrontab(5) and anacrontab(8) as well.

Supporting material: date and time settings

Before working with a scheduling system, we need to know how to view and modify the system date and time. To check the system date and time maintained by the kernel, use the date command. With no arguments, it displays the current values. You can also modify the date/ time as root

Note: The date/time argument can be presented as either a string or as a numeric argument. See man date for the complete details.

  • Examples using a string To change the date and time using a string argument use the date command with the -s option.

    • Example #1: set the time using the current date

      date -s "12:00"

    • Example #2: set the date using the current year

      date -s "Feb 16"

    • Example #3: set the complete date and time

      date -s "Feb 16 2004 12:00:59"

  • Examples using a numeric argument using the standard format mmddhhmm[[cc]yy][.ss] without -s:

    • Example #4: set the date and time using the current year

      date 02161200

    • Example #5: no century number (bad) followed by setting the date with century (good) and time

      date 0216120004

      date 021612002004

    • Example #6: set the complete date and time, with seconds

      date 021612002004.45

Note: To check the date and time that is maintained by the hardware use the hwclock command, but use it carefully on a real (not virtual) machine.

Exercise #1: Cron scheduling

Do this exercise first as a normal user and again as root.

The crond daemon is used to schedule jobs that run periodically, using a schedule based on minute / hour / day-of-month (dom) / month / day-of-week (dow). Jobs submitted usingthe system crontab file in /etc will run at the scheduled time until they are removed from the cron queue.

Verify that the cron daemon, crond, is
running and show the command used: ______________ ________________________________

Analyzing a cron job

# min hour dom month dow [userid] command

0,*/15 8-20 24,25 12 * root echo "From crontab" > /root/out

What does this cron job do? Change the date/time in order to execute it now.

_______________________________________________________________________________________

_______________________________________________________________________________________

Creating / submitting a cron job as a user

The crontab utility is used to allow users to submit jobs to cron. The crontab utility can perform a number of actions, such as:

-l

list current cron job file

-e

edit/create cron job file

-r

remove cron job file

See man 1 crontab for the switches to perform crontab command actions. For more details on cron syntax, see man 5 crontab.

Creating/Modifying a cron job

Removing a cron job

Crontab access

You should experiment with the files /etc/cron.allow and /etc/cron.deny to control who can submit cron jobs using the crontab command.

The format of both access control files is one line per user, specifying the userid. The cron control files are read each time a user tries to create/modify a cron job. If the file cron.allow exists, only users listed in it are allowed to use cron, and the cron.deny file is ignored. If cron.allow does not exist, all users listed in cron.deny are not allowed to use cron. Note: The root user can always use cron.

Exercise #2: Viewing the system cron jobs

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Section C - Service management

Supporting commands

runlevel

display the previous and current runlevels

telinit n,

switch to runlevel n

uname

display basic system information

chkconfig

manage runlevel services with the following options


--list [service]

list the state of one or all services in all runlevels; a state can be on or off

--level n service on

change the state of a runlevel service on in the specified runlevel

--level n service off

change the state of a runlevel service off in the specified runlevel

--add service

add the service to the runlevels based on the defaults

--del service

remove the service from all runlevels

Exercise #1: Viewing a runlevel service

Exercise #2: Turning a service on & off