Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* daemon construction
@ 1998-06-01  4:00 Dirksen E. Bussiere [42T]
  1998-06-02  4:00 ` Carl Beckner
  0 siblings, 1 reply; 2+ messages in thread
From: Dirksen E. Bussiere [42T] @ 1998-06-01  4:00 UTC (permalink / raw)



I need to write a daemon which will run in the background on our
alphaserver 4100 and monitor the execution of certain software
tasks.  In essence, it will be a fancy queue manager.  I've 
written such programs before, but they were on smaller systems and
in assembler (utilizing NMI's).  I want to write this one in C.
Does anyone know where I can find any source code examples of this
kind of program for the alpha, or of any examples?  Thanks.

-Dirk


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Dirk Bussiere                 bussierd@tvsfrank.pprd.abbott.com 
Abbott Laboratories             Office: (847)935-0916
Department 42T                  FAX:    (847)937-2625
Scientific Information, Analysis, and Management/
Dept. of Structural Biology
100 Abbott Park Rd.
Abbott Park, IL   60064-3500
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: daemon construction
  1998-06-01  4:00 daemon construction Dirksen E. Bussiere [42T]
@ 1998-06-02  4:00 ` Carl Beckner
  0 siblings, 0 replies; 2+ messages in thread
From: Carl Beckner @ 1998-06-02  4:00 UTC (permalink / raw)



Dirksen E. Bussiere [42T] wrote:
> 
> I need to write a daemon which will run in the background on our
> alphaserver 4100 and monitor the execution of certain software
> tasks.  In essence, it will be a fancy queue manager.  I've
> written such programs before, but they were on smaller systems and
> in assembler (utilizing NMI's).  I want to write this one in C.
> Does anyone know where I can find any source code examples of this
> kind of program for the alpha, or of any examples?  Thanks.

Essentially you need 2 things. First, you need a little script to
start your daemon when the system boots. On Digital UNIX, the convention
is to put this script in /sbin/init.d, then create a link in
/sbin/rc3.d to the script. The script should begin with an upper case
"S" to indicate it is used on startup. Here is an example of a script
I use.

	#!/sbin/sh
	#
	# Start robot control program

	#
	# Start ssqzym
	#
	if [ -x /usr/bin/ssqzym ]; then
	        /usr/bin/ssqzym >/dev/null 2>&1 &
	        /bin/echo "Robot control program started"
	fi


Then you need a little bit of code in your daemon to make sure it runs
in the background, closes the connection to the controlling terminal,
etc.
Here is the routine I use for that.

	void daemon_init (void)
	{
 	   pid_t pid;
 	   char        buff[80];

	    if ((pid = fork ()) < 0)
	    {
	        errlog ( "Error forking ourself as a daemon process - exiting"
);
	        exit ( 1 );
	    }
	    else if (pid != 0)
	    {
	        sprintf ( buff, "Parent has forked child %d - exiting\n", pid
);
	        errlog ( buff );
	        exit ( 0 );
	    }

	/*
	 * Set the process & session ID
	 * also releases the controlling terminal
	 */
	    setsid();
	    setpgrp();

	/*
	 * Change to a known valid directory
	 */
	    chdir ("/");
	    umask (0);
	}


Hope this helps.

Carl
-- 
Carl Beckner             becknerc@dinker.pprd.abbott.com
Abbott Laboratories      Phone:  847-938-2217
Dept 42T;  Bldg AP31     Fax  :  847-938-9226
200 Abbott Park Rd
Abbott Park, Il 60064



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-06-02  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-06-01  4:00 daemon construction Dirksen E. Bussiere [42T]
1998-06-02  4:00 ` Carl Beckner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox