ejkst@cisunx.UUCP (Eric J. Kennedy) (07/01/88)
Well, I was monitoring an experiment in the lab until the wee hours of
the morning, and started thinking...
"Wouldn't it be nice if...
I could run things from batch files, either attended or
unattended, without having to worry about whether there's enough
ram available?"
So...
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# enough.man
# enough.c
# enough.uu
# launch
# launch.sh
# This archive created: Fri Jul 1 03:28:05 EDT 1988
# By: Eric Kennedy
echo shar: extracting enough.man '(2272 characters)'
cat << \SHAR_EOF > enough.man
Enough AMIGA PROGRAMMER'S MANUAL Enough
NAME
Enough - test for the availibility of ram.
SYNOPSIS
Enough TOTAL [CHIP]
DESCRIPTION
This short command makes launching applications via batch files a
little safer. We all know that the Amiga should be able to handle a
situation where your memory is running low and you try to start an
application that requires more ram than you have free, or more chip ram
than you have free. A well written program will let you know of the
situation, if possible, and exit properly. If there isn't even enough
ram free to load the program, AmigaDOS should safely exit with the
ever-so-intelligible "not an object module."
We also all know that this doesn't always happen, or that the low memory
situation will cause problems elsewhere in the system. The Amiga simply
doesn't like to be low on memory.
Enough's uses include those "setup" types of files, where you
rez -l make cc ln as
or
run preview
run mg
tex -R
or the ever popular AmiCron, where you could run MRBackup every Monday
afternoon at 3:00, provided there's enough ram.
EXAMPLE
Enough 200000 100000
will test for the existance of 200000 bytes of ram, 100000 of which
must be chip ram. If there is enough, enough will exit with a return
code of 0; if there isn't, it will exit with a return code of 10.
Very simple. If you look at the source code, you'll see just how
simple.
Two very simple examples are provided. Launch is an execute script,
and launch.sh is a script for Matt Dillon's shell.
AUTHOR
Eric Kennedy ejkst@cisunix.edu
BUGS
How could anything so short have bugs?
Enough simply compares your requested amount with the amount in the
system, so it is up to you to provide your own safety margins.
Experiment first, using pm or shell or mclk, or some other utility that
provides seperate reports for fast, chip, and total. Run your system
down do what you think the minimum is and see if there's a problem
running your application.
SHAR_EOF
if test 2272 -ne "`wc -c enough.man`"
then
echo shar: error transmitting enough.man '(should have been 2272 characters)'
fi
echo shar: extracting enough.c '(1317 characters)'
cat << \SHAR_EOF > enough.c
/**************
*
* Enough.c - Tests for the presence of a specified amount of free total ram and
* free chip ram.
*
* Synopsis - enough TOTAL [CHIP]
*
* Returns - 0 if enough total ram and chip ram is available.
* 10 (AmigaDOS ERROR level) if enough total ram or chip ram is not
* available.
*
* Author - Eric Kennedy ejkst@cisunx.edu
*
* Status - public domain
*
**************/
#include <exec/memory.h>
main(argc,argv)
char *argv[];
{
long freechip, freefast;
extern long AvailMem();
long reqchip = 0L;
long reqtot;
extern long atol();
if(argc>1) /* Is there a first argument? */
{
reqtot = atol(argv[1]);
if(argc > 2) /* Is there a second argument? */
reqchip = atol(argv[2]);
}
else
exit(20); /* no error message--keep it small */
Forbid(); /* get available memory */
freechip = AvailMem (MEMF_CHIP);
freefast = AvailMem (MEMF_FAST);
Permit();
/* compare to requested mem */
if((freechip >= reqchip) && (freechip+freefast >= reqtot))
exit(0); /* there was enough */
else
exit(10); /* there wasn't enough */
}
SHAR_EOF
if test 1317 -ne "`wc -c enough.c`"
then
echo shar: error transmitting enough.c '(should have been 1317 characters)'
fi
echo shar: extracting enough.uu '(3199 characters)'
cat << \SHAR_EOF > enough.uu
begin 644 enough
M #\P # ( () ,0 $ /I ""4[Z 21.
M5?_P0JW_] QM $ "&\N(&T "B\H 1.N@""6$\K0/_P#&T @ (;Q(@;0 *
M+R@ "$ZZ &A83RM __1@"C\\ !1.N@6 5$].N@=82'@ DZZ!QI83RM __Q(
M> $3KH'#%A/*T#_^$ZZ!W @+?_\L*W_]&T8(BW__-*M__BRK?_P;0I"9TZZ
M!3Q43V */SP "DZZ!3!43TY=3G5.5?_\2.<(("1M @,$@ @9P8,$@ )9@12
MBF#P> ,$@ M9@9X 5**8 @,$@ K9@)2BD*M__Q@)"!*4HH0$$B 2,!R"B\
M("W__$ZZ _(D']2 E+P P*T+__! 22(!20$'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\ !"QL@(I.[O\H3OH B)O 0L;("*3N[^8DSO , !"QL
M@(I.[O\Z(F\ !"QL@(I.[O[:3OH BQL@(I.[O]\(F\ !" O @L;("*3N[_
M+B!O 0L;("*3N[^C"QL@(HB;P $("\ "$[N_=@L;("*3N[_=B)O 0L;("*
M3N[^AB!O 0L;("*3N[^@$SO P !"QL@+I.[O^@(&\ !"QL@+I.[O^F(&\
M!"QL@+I.[O^R #[ $ ! !F@ /R #Z@ "$ (" @
M(" @(" @,# P,# @(" @(" @(" @(" @(" @(""00$! 0$! 0$! 0$! 0$!
M# P,# P,# P,#$! 0$! 0$ )"0D)"0D! 0$! 0$! 0$! 0$! 0$! 0$! 4!
M0$! 0 H*"@H*"@(" @(" @(" @(" @(" @(" @("0$! 0" !0 /R #
)ZP $ /R
end
SHAR_EOF
if test 3199 -ne "`wc -c enough.uu`"
then
echo shar: error transmitting enough.uu '(should have been 3199 characters)'
fi
echo shar: extracting launch '(98 characters)'
cat << \SHAR_EOF > launch
failat 20
enough 300000 100000
if not error
run ue
else
echo "Not enough memory for Uedit"
endif
SHAR_EOF
if test 98 -ne "`wc -c launch`"
then
echo shar: error transmitting launch '(should have been 98 characters)'
fi
echo shar: extracting launch.sh '(99 characters)'
cat << \SHAR_EOF > launch.sh
enough 300000 100000
if $_lasterr < 10 ; run ue ; else ; echo Not enough memory for Uedit ; endif
SHAR_EOF
if test 99 -ne "`wc -c launch.sh`"
then
echo shar: error transmitting launch.sh '(should have been 99 characters)'
fi
# End of shell archive
exit 0
--
------------
Eric Kennedy
ejkst@cisunx.UUCP