From owner-freebsd-questions Thu Mar 6 12:52: 4 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 32D1437B401 for ; Thu, 6 Mar 2003 12:52:02 -0800 (PST) Received: from mail.broadpark.no (mail.broadpark.no [217.13.4.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 80A3B43FA3 for ; Thu, 6 Mar 2003 12:52:01 -0800 (PST) (envelope-from junkmail@sensewave.com) Received: from tove (la3sg.net [217.13.29.172]) by mail.broadpark.no (Postfix) with ESMTP id 07869787D8; Thu, 6 Mar 2003 21:52:00 +0100 (MET) From: "Kjell" To: "J. Seth Henry" Date: Thu, 6 Mar 2003 21:52:11 +0100 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Looking for POSIX programming resources Reply-To: la3sg@sensewave.com Cc: questions@freebsd.org Message-ID: <3E67C30B.30138.312575D@localhost> In-reply-to: <20030306150225.S940-100000@whitetower.gambrl01.md.comcast.net> X-mailer: Pegasus Mail for Win32 (v3.12c) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > I realize this isn't exactly on topic, but I figure a bunch of you > guys/gals have probably done stuff like this, and might know where to > point me. > > I am trying to write an automation program in FreeBSD that listens for > commands on a serial port, and responds by issuing commands in response. I > also need to accept commands and data from local users or shell scripts. > > Right now, I poll the serial ports periodically, and this seems to work > OK. I would prefer to put the program to sleep until either a fixed amount of > time has passed ( a timer interrupt ), or data arrives at one of the > serial ports ( a device interrupt ). Unfortunately, I don't know how to do > to this under FreeBSD. (All my C programming so far has been "filters" > and such). Could someone point me to a resource on how to do this? > > Also, this program should run as a daemon, but I don't know how to make it > disconnect from the tty (currently, I just run it using &). bkpupsd is a simple port that demonstrates this. > > How can I call programs, and read their output, from within my program? > > How can I read the system clock? A lot of events need to occur based on > real-time (I presently use cron and shell scripts, but I would like to be > able to calculate future times programmatically, and set my own "alarms") long int unixtid; time(&unixtid); > > Lastly, how can I get data and commands into and out of my program? I Also demonstrated by bkpupsd > figure a file interface would be the simplest, and simply check the file > periodically to see if it has changed. Is there an easier way, or is this > an accepted method? I would eventually like to write a web page and use my > existing web server and CGI scripts to control/monitor the daemon - but > I'm not sure I'm ready to write my own web server code into this app. You will find that PHP scripts lends itself fine for this.. > > In summary, can anyone help me write code that: > 1) puts my daemon to sleep, awaking only when either a timer has expired, > data has arrived one of the controlled serial ports, or the user has > invoked some interface from a script or command line utility. > > 2) Daemonizes my program (dissasociating itself from the terminal) > > 3) Accepts commands and/or data from scripts or command line utilities. > > 4) Call other programs, and pass them parameters. > > 5) Read the system clock. The above should answer your questions? regards from Kjell / LA3SG To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message