SIGALRM Help

A Unix system command needs to be executed from a C/C++ program. How do I use the SIGALRM in this case to stop processing the command after a few sec.
For eg, if the command is to connect to a database and the server is down, I would want to try for say 15 sec then give a timeout error.
How do I code this ?

Most commands already have a timeout built-in to them. I would just go with that.

But to do what you asked, I would:

1 fork()

2a the child process would exec() the command in question

2b the parent process would sleep(15) ; then kill its child