Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Mar 2003 15:22:16 -0500 (EST)
From:      "J. Seth Henry" <jshenry@comcast.net>
To:        questions@freebsd.org
Subject:   Looking for POSIX programming resources
Message-ID:  <20030306150225.S940-100000@whitetower.gambrl01.md.comcast.net>

next in thread | raw e-mail | index | archive | help
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 &).

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")

Lastly, how can I get data and commands into and out of my program? I
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.

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.

Like I said, presently I have a program which manages to work around the
above issues, but it requires a lot more CPU than I believe is necessary
(and I'd like to learn how to do it). My code so far has been written in
ANSI C. IOW - I know how to program "in general", I'm just a little fuzzy
on how I talk to the operating system beyond stdin and stdout.

If this discussion belongs elsewhere, please, point me in the right
place! I'm also open to books, if anyone has any recommendations. Is
there a "Programming POSIX for dummies" out there?

Many thanks,
Seth Henry


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030306150225.S940-100000>