To run the Unix database server in the background, and to enable it to run independently of the current session, you run it as a daemon.
If you use the Unix & (ampersand) command to run the database server in the background, it will not work—the server will either immediately shut down or stop responding. You must instead run the database server as a daemon.
As well, attempting to start a server in the background from within a program using the typical fork()-exec()
sequence will not work. If you need to do this, add the -ud option to the list of database server options.
You can run the Unix database server as a daemon in one of the following ways:
Use the -ud option when starting the database server. For example:
dbsrv11 -ud demo |
Use the dbspawn tool to start the database server. For example:
dbspawn dbsrv11 demo |
One advantage of using dbspawn is that the dbspawn process does not shut down until it has confirmed that the daemon has started and is ready to accept requests. If for any reason the daemon fails to start, the exit code for dbspawn will be non-zero.
When you start the daemon directly using the -ud option, the dbeng11 and dbsrv11 commands create the daemon process and return immediately (exiting and allowing the next command to be executed) before the daemon initializes itself or attempts to open any of the databases specified in the command.
If you want to ensure that a daemon is running one or more applications that will use the database server, you can use dbspawn to ensure that the daemon is running before starting the applications. The following is an example of how to test this using a csh script.
#!/bin/csh # start the server as a daemon and ensure that it is # running before you start any applications dbspawn dbsrv11 demo if ( $status != 0 ) then echo Failed to start demo server exit endif # ok, now you can start the applications ... |
This example uses an sh script to test whether the daemon is running before starting the applications.
#!/bin/sh # start the server as a daemon and ensure that it is # running before you start any applications dbspawn dbsrv11 demo if [ $? != 0 ]; then echo Failed to start demo server exit fi # ok, now you can start the applications ... |
Spawn a daemon from within a C program, for example:
... if( fork() == 0 ) { /* child process = start server daemon */ execl( "/opt/sqlanywhere11/bin/dbsrv11", "dbsrv11", "-ud", "demo" ); exit(1); } /* parent process */ ... |
Note that the -ud option is used.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |