I have been running mprime on Linux for some time and have recently written a script 
to make it run as a daemon on startup. mprime automatically nice's itself, which is 
very neat and makes it ideal for running this way.

On my Debian 2.2 system:

Copy the enclosed script to: /etc/init.d/mprime.sh

You need to then create symlinks in the following locations:
/etc/rc0.d/K01mprime
/etc/rc1.d/K01mprime
/etc/rc2.d/S99mprime
/etc/rc6.d/K01mprime

Don't forget rc6.d! I did at first and spent some time being very confused.


Points to bear in mind:

Running mprime in a separate user account may be a good idea. This is because:
1. It is protected from anything you may do in your own user space. You can't 
accidently kill it or delete its files. In the script I am running it as myself, 
although this is a whole lot better than root.
2. Depending on your file permissions, other user accounts would be protected in the 
unlikely case of there being a destructive bug in mprime, or any sort of exploitation 
from the remote server. (Okay, the latter is very unlikely, but I work in Internet 
security so it's always on my mind!)

Where compute intensive tasks are running:
1. Although not explicitly tested I presume that both tasks would be penalised by the 
scheduler down to the lowest priority, and hence each would get 50% of the remaining 
CPU time. This would impact any performance intensive games, for instance, so running 
mprime as a daemon may not be such a good idea if you need to be able to turn it on 
and off regularly.
2. The performance penalty will be worse than this, because some cache thrashing would 
occur as the scheduler switches between tasks.



I have also included my earlier prime.sh script which I wrote for manually controlling 
the mprime program. This is what I used before deciding the daemonise it. I made some 
improvements for the daemon which aren't in this script, but you can edit those in. 
I've pasted the scripts inline as I'm not sure whether attachments are allowed.


**** Start of mprime.sh ****


#!/bin/sh
#
# mprime.sh     Script to manage "mprime" prime factoring program.
#
# Version:      1.1     11-Nov-2000     Gareth Randall
#

PRIME_BIN_FILE=/home/gareth/mprime/mprime
PRIME_LOG_FILE=/home/gareth/mprime/log/mprime.log
DESC="prime factoring program"
NAME=mprime

if !(test -f $PRIME_BIN_FILE) ; then
   echo "Couldn't find $NAME binary: $PRIME_BIN_FILE" >&2
   exit 1;
fi

case "$1" in
   start)
         if (pidof $PRIME_BIN_FILE > /dev/null ) ; then
            echo "ABORTING: Process with that binary already running!" >&2
            exit 1;
         fi

         echo -n "Starting $DESC: "
         echo -n "START: " >> $PRIME_LOG_FILE
         date >> $PRIME_LOG_FILE

         su gareth -c "$PRIME_BIN_FILE -d >> $PRIME_LOG_FILE &"

         echo "$NAME."
         ;;
   stop)
         echo -n "Stopping $DESC: "

         killall -2 $PRIME_BIN_FILE

         echo -n "STOP : " >> $PRIME_LOG_FILE
         date >> $PRIME_LOG_FILE
         echo "$NAME."
         ;;
   *)
         echo "Usage: $0 {start|stop}" >&2
         exit 1
         ;;
esac

exit 0

**** End of mprime.sh ****


**** Start of prime.sh ****

#!/bin/sh
PRIME_BIN_FILE=/home/gareth/mprime/mprime
PRIME_LOG_FILE=/home/gareth/mprime/log/mprime.log

if (pidof $PRIME_BIN_FILE) ; then
   echo "ABORTING: A process with that executable is already running!"
   exit 1;
fi

if !(test -f $PRIME_BIN_FILE) ; then
   echo "Couldn't find mprime binary: $PRIME_BIN_FILE"
   exit 1;
fi

date >> $PRIME_LOG_FILE
$PRIME_BIN_FILE -d | tee -a $PRIME_LOG_FILE

**** End of prime.sh ****


Hope someone finds these useful!

Yours,

======= Gareth Randall =======

_________________________________________________________________________
Unsubscribe & list info -- http://www.scruz.net/~luke/signup.htm
Mersenne Prime FAQ      -- http://www.exu.ilstu.edu/mersenne/faq-mers.txt

Reply via email to