Subject: Handling signals
To: None <netbsd-users@netbsd.org>
From: Benjamin Walkenhorst <krylon@gmx.net>
List: netbsd-users
Date: 12/24/2003 16:35:14
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello everybody,

I have written a program that writes output to a log file (via=20
fprintf()). When I stop the program (which runs in background) via=20
kill, the last line of output sometimes is not written completely into=20
the file.
I use a perl-script to control the program which starts the program by=20
reading the logfile's last line and passing part of it as a=20
command-line-argument to the program.
When reading such an incomplete line, sometimes processing the line=20
fails or the program is started with an incorrect parameter. So I would=20
like to make sure, the program does not quit while writing a line to=20
the logfile.
I think I remember you can do this in shell-scripts via the=20
"trap"-command. With trap, if I remember correctly, you can catch a=20
signal and define an action to handle it. Can I do such a thing in C?=20

I almost sure I can, but how? I also guess this is not quite the right=20
place to ask, but I am not sure where to look.=20
I found out there's ways to handle signals both on the system-level and=20
included in the libraries, but I am a rather poor programmer (it's just=20
for fun), so I did not find the man-pages to be that helpful, since I=20
lack the background knowledge.=20
Where should I start looking? (a brief answer how to get my problem=20
solved might be nice, but I also want to understand what I am doing and=20
I rather like reading...)=20
I have a copy of "The C Programming Language 2nd Edition", but it just=20
mentions signals briefly in the appendix on the libraries... ;-/=20

Thank you very much,

Merry Christmas,

Benjamin

- --=20
Benjamin Walkenhorst
eMail: krylon@gmx.net
http://www.krylon.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQE/6bI5/JWwsvZUqOwRAryOAKCPfJ5ygi6b7/zm7Uu3iuuz+5IzVwCgxMuS
HB2t7PbzVW5x/PmcQcODeg4=3D
=3DIzc0
-----END PGP SIGNATURE-----