home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
c
/
cron093.zip
/
CRON.DOC
< prev
next >
Wrap
Text File
|
1992-10-07
|
5KB
|
120 lines
cron.exe 0.90 (BETA) - a clock daemon for OS/2 2.0
Designed and written by Ken Miller - 1:134/111
Copyright (c) 1992 Shetland Computer Services
-------------------------------------------------------------------------
cron is an OS/2 implementation of the Unix utility cron. Based on a
crontab file (a listing of times, dates, and programs to run) cron
will schedule these jobs to run at their designated times. cron is
not an exact duplicate of the Unix cron - some liberties have been
taken, so please be sure to look at the example source file for the
differences.
Setting up cron is very simple. In your startup.cmd, use the start
command to start cron. Use something like this:
start "CRON - Clock Daemon" /win /c c:\bin\cron.exe c:\bin\crontab
This command will start cron as a full screen session, and read in
c:\os2bin\crontab and immediately start processing.
NOTE: do not use RUN= in your config.sys or DETACH from the command
line. These two techniques do not work (yet), and are not
supported.
How does it work?
----------------
The 'simple' way of writing a program like this is to write a polling
loop, which loops until an event is ready to run. Under OS/2, a
program like this would be an absolute pig, since it would fully use
all of its alloted time *every* cpu slice. Most programs, when
properly written, do NOT require the CPU all the time.
Enter threads, queues, and semaphores. OS/2 has implemented some nice
features that do not exist in current flavours of Unix (other than the
Mach kernal), such as threads and semaphores. These options allow a
program to efficiently use the cpu without to much grief on the part
of the programmer.
cron is a two-thread program. Thread-1, which is always the 'main'
thread of any OS/2 program, runs the scheduler. An asyncronous
one-shot timer is created which lasts for 1 minute. Every minute
thread-1 checks to see if there are any jobs to run. Once the check
has completed, another async timer is created, and so on.
If an event is found to run, thread-1 does not spawn a process to run
the program, since this can take upwards of 1-2 seconds to perform.
Instead, a message is written to a queue.
Thread-2 spends most of its time sleeping. When cron is started,
thread-2 is created, and it immediately sees if is has any programs to
spawn (it does this by reading a process queue). If nothing is in the
queue, thread-2 goes to sleep.
When thread-1 writes something to the queue, thread-2 wakes up, reads
the queue, and spawns off the process. It the reads the queue again,
and so the process continues (or is that thread?).
So, what you get is a thread which wakes up every minute, scans an
internal list, and sends messages to thread-2 to spawn off processes.
If you run pulse.exe, and the run cron, you should hardly notice any
impact on your system, since cron spends almost 99% of the time
sleeping. However, if you are spawning off lots of jobs, you will of
course cause some impact. This isn't cron's fault - it's the creation
of new processes which takes time.
Future Plans:
------------
Well, there is only so far you can take a program like cron. It is
basically a finished product, but there are a few things to add to it:
i) better explanation of error codes returned from the spawn of the
specified processes. rc=2 just isn't self explanatory.
ii) disable killing the program via the keyboard. If this is to be a
true daemon, you should not be able to kill this program with
SIGINTs.
iii) instead of being a 'startable' process, it should be a
'detach'able process. Right now, this program does not work
properly when detached. This is currently being investigated.
iv) perhaps a change in the cron grammar to allow crontab entries to be
split across two lines, to make the file easier to read.
v) this one is left open for you. If you have any suggestions,
please feel free to drop me a line. I can't promise anything,
but I will look at all sugestions.
How much does it cost?
---------------------
As a rather well-known PC Fractal programming team says,
"Don't want money. Got money. Want admiration".
This program is free, but it is not freeware - it is shareware. This
means that while you can use the program for free (since I don't want
any money) the program does remain the intellectual property of Ken
Miller and Shetland Computer Services. It is meant for use only in
non-commerical environments. If you wish to use this program in a
commerical environment, contact Ken Miller at 1:134/111 (FidoNet).
Oh, if you do use this program, I'd appreciate it if you would drop me
a line and let me know! Feel free to give this program to other
people. They might find it useful!
Disclaimer
----------
Ken Miller and Shetland Computer Services will not be held responsible
for any damage caused by the use of cron, either directly or
indirectly. You use the program at your own risk!