Home > Articles > Operating Systems, Server > Solaris

This chapter is from the book

6.5 Scheduling Processes

From the user or system administrator's perspective, scheduling processes includes assigning priorities to the processes based on their importance and the need, executing a job at a time when the user will not be physically present at the system to manually start the job, distributing the job load over time, and executing a job repeatedly in a periodic fashion without manually having to start it each time.

Of the four tasks mentioned previously, the use of the nice and renice commands to assign priorities to the processes was described earlier in this chapter. Using these commands, you can increase the priority of a process that you want to complete faster. Similarly, if there is a long process taking most of the CPU time and it is not important to get this process done fast, you can use these commands to reduce its priority so that other process will get to run more.

For the other three tasks, use the crontab utility and the at command described below.

6.5.1 cron Utility

The cron utility is a general Unix utility named after Chronos (meaning "time"), the ancient Greek god of time. It allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in Solaris.

Crontab (CRON TABle) is a file that contains commands, one per line, that are read and executed by the cron daemon at the specified times. Each line or entry has six fields separated by space characters. The beginning of each line contains five date and time fields that tell the cron daemon when to execute the command. The sixth field is the full pathname of the program you want to run. These fields are described in Table 6.10.

Table 6.10. The crontab File

Field

Description

Values

1

Minute

0 to 59. A * in this field means every minute.

2

Hour

0 to 23. A * in this field means every hour.

3

Day of month

1 to 31. A * in this field means every day of the month.

4

Month

1 to 12. A * in this field means every month.

5

Day of week

0 to 6 (0 = Sunday). A * in this field means every day of the week.

6

Command

Enter the command to be run.

The first five fields can also use any one of the following formats:

  • A comma separated list of integers, like 1,2,4 to match one of the listed values.
  • A range of integers separated by a dash, like 3-5, to match the values within the range.

The following are some examples of entries in the crontab file.

Example 6.1: Reminder

0 18 1,15 * * echo "Update your virus definitions" > /dev/console

This entry displays a reminder in the user's console window at 5.00 p.m. on 1st and 15th of every month to update the virus definitions.

Example 6.2: Removal of Temporary Files

30 17     *    *     *         rm /home/user_x/tmp/*

This entry removes the temporary files from /home/user_x/tmp each day at 5:30 p.m.

The crontab files are found in the /var/spool/cron/crontabs directory. All the crontab files are named after the user they are created by or created for. For example, a crontab file named root is supplied during software installation. Its contents include the following command lines:

10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
  • The first command line instructs the system to run logchecker everyday at 3:10 a.m.
  • The second command line orders the system to execute nfsfind on every Sunday at 3:15 a.m.
  • The third command line runs each night at 3:30 a.m. and executes the gsscred command.
  • The fourth command is commented out.

Other crontab files are named after the user accounts for which they are created, such as puneet, scott, david, or vidya. They also are located in the /var/spool/cron/crontabs directory.

When you create a crontab file, it is automatically placed in the /var/spool/ cron/crontabs directory and given your user name. You can create or edit a crontab file for another user, or root, if you have superuser privileges.

6.5.1.1 Creating and Editing crontab Files

You can create a crontab file by using crontab -e command. This command invokes the text editor that has been set for your system environment. The default editor for your system environment is defined in the EDITOR environment variable. If this variable has not been set, the crontab command uses the default editor, ed, but you can choose an editor that you know well.

The following example shows how to determine if an editor has been defined, and how to set up vi as the default.

$ echo $EDITOR
$
$ EDITOR=vi
$ export EDITOR
               

If you are creating or editing a crontab file that belongs to root or another user, then you must become superuser or assume an equivalent role.

You do not need to become superuser to create or edit your own crontab file. The following are the steps to create a new or edit an existing crontab file:

  1. Create a new crontab file, or edit an existing file.
    $ crontab -e [username]
          

The username specifies the name of the user's account for which you want to create or edit a crontab file. If you want to operate on your own crontab file then leave this option blank ($ crontab -e).

  1. Add command lines to the crontab file. Follow the syntax described in Table 6.10.
  2. Save the changes and exit the file. The crontab file will be placed in the /var/spool/cron/crontabs directory.
  3. Verify your crontab file changes.
    # crontab -l [username]
          
    The contents of the crontab file for user <username> will be displayed.
    $ crontab -l
          
    The contents of your crontab file will be displayed.

6.5.1.2 Removing Existing crontab Files

You can use the crontab -r command to remove any existing crontab file. As noted previously, to remove a crontab file that belongs to root or another user, you must become superuser or assume an equivalent role.

# crontab -r [username]

This will remove the crontab file for user <username>, if any.

$ crontab -r

This will remove your existing crontab file, if any.

6.5.1.3 Controlling Access to crontab

You can control access to crontab by modifying two files in the /etc/cron.d directory: cron.deny and cron.allow. These files permit only specified users to perform crontab tasks such as creating, editing, displaying, and removing their own crontab files. The cron.deny and cron.allow files consist of a list of user names, one per line. These access control files work together in the following manner:

  • If cron.allow exists, only the users listed in this file can create, edit, display, and remove crontab files.
  • If cron.allow doesn't exist, all users may submit crontab files, except for users listed in cron.deny.
  • If neither cron.allow nor cron.deny exists, superuser privileges are required to run crontab.

Superuser privileges are required to edit or create cron.deny and cron.allow.

During the Solaris software installation process, a default /etc/cron.d/ cron.deny file is provided. It contains the following entries:

  • daemon
  • bin
  • nuucp
  • listen
  • nobody
  • noaccess

None of the users listed in the cron.deny file can access crontab commands. The system administrator can edit this file to add other users who are denied access to the crontab command. No default cron.allow file is supplied. This means that, after the Solaris software installation, all users (except the ones listed in the default cron.deny file) can access crontab. If you create a cron.allow file, the only users who can access crontab commands are those whose names are specified in this cront.allow file.

For more information, see the crontab man page.

6.5.2 The at Command

Unlike the cron utility, which allows you to schedule a repetitive task to take place at any desired regular interval, the at command lets you specify a one-time action to take place at some desired time. For example, you might use crontab to perform a backup each morning at 4 a.m. and use the at command to remind yourself of a meeting later in the day.

6.5.2.1 Creating an at Job

To submit an at job, type at and then specify an execution time and a program to run, as shown in the following example:

# at 09:20am today
at> who > /tmp/log
at> <Press Control-d>
job   912687240.a       at    Thu    Jun  30    09:20:00

When you submit an at job, it is assigned a job identification number (912687240 in the case just presented), which becomes its filename along with the .a extension. The file is stored in the /var/spool/cron/atjobs directory.

The cron daemon controls the scheduling of at files similar to the way it does for crontab jobs.

The command syntax for at is shown here:

at [-m] <time> <date>

The at command syntax is described in Table 6.11.

Table 6.11. at Command Syntax

Option

Description

-m

Sends you mail after the job is completed.

<time>

The hour when you want to schedule the job. Add am or pm if you do not specify the hours according to a 24-hour clock (midnight, noon, and now are acceptable keywords). Minutes are optional.

<date>

The first three or more letters of a month, a day of the week, or the keywords today or tomorrow.

By default, users can create, display, and remove their own at job files. To access at files that belong to root or other users, you must have superuser privileges.

Following is an example of creating an at job:

$ at -m 2130
  at> rm /home/jonny/*.backup
  at> <Press Control-D>

  job  897355800.a  at  Thu Jun 30  21:30:00 2009

This shows the at job that user jonny created to remove his backup files at 9:30 p.m. He used the -m option so that he would receive an email message after the job is done.

6.5.2.2 Checking Jobs in Queue

To check your jobs that are waiting in the at queue, use the atq command. This command displays status information about the at jobs you created. You can also use the atq command to verify that you have created an at job. The atq command confirms that at jobs have been submitted to the queue, as shown in the following example:

$ atq

Rank        Execution Date          Owner       Job   Queue  Job Name
1st         Jun 30, 2009 09:20      root  912687240.a  a     stdin
2nd         Jun 30, 2009 21:30      jonny 897355800.a  a     stdin

Another way to check an at job is to issue the at -1 command. This command shows the status information on all jobs submitted by a user, or for a particular job whose id is specified. The command syntax is as follows:

$ at -l [job-id]

The <job-id> is the identification number of the job whose status you want to display. If no <job-id> is specified, then status information on all jobs submitted by this particular user is displayed.

Following is an example using at -l command:

$ at -l
897543900.a     Sat Jul 14 23:45:00 2004
897355800.a     Thu Jul 12 19:30:00 2004
897732000.a     Tue Jul 17 04:00:00 2004

6.5.2.3 Removing Existing at Jobs

You can use the at -r command to remove any existing at job. Once again, to remove an at job that belongs to root or another user you must become superuser or assume an equivalent role. You do not need to become superuser or assume an equivalent role to remove your own at job.

# at  -r [job-id]

This will remove the job with identification number job-id.

Verify that the at job has been removed by using the "at-1" or atq command to display the jobs remaining in the at queue. The job whose identification number you specified should not appear.

In the following example, a user wants to remove an at job that was scheduled to execute at 4 a.m. on July 17th. First, the user displays the at queue to locate the job identification number. Next, the user removes this job from the at queue using the at -r command. Finally, the user verifies that this job has been removed from the queue using the at -l command:

$ at -l
897543900.a     Sat Jul 14 23:45:00 2003
897355800.a     Thu Jul 12 19:30:00 2003
897732000.a     Tue Jul 17 04:00:00 2003
$ at -r 897732000.a
$ at -l 897732000.a
at: 858142000.a: No such file or directory

6.5.2.4 Controlling Access to at

You can set up a file to control access to the at command, permitting only specified users to create, remove, or display queue information about their at jobs. The file that controls access to at is /etc/cron.d/at.deny. It consists of a list of user names, one per line.

The users listed in this file cannot access at commands. The default at.deny file, created during the Solaris OS software installation, contains the following user names:

  • daemon
  • bin
  • smtp
  • nuucp
  • listen
  • nobody
  • noaccess

With superuser privileges, you can edit this file to add other user names whose at access you want to restrict.

For more information, see the at(1) man page.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020