a daemon is a process that has init (the father of all processes) as direct father . So it runs in the background and is not attouched to a terminal. Most servers are daemons, they don't use a terminal.
when you execute a program from a console, look at how the "family tree" goes
init ------> console ------->your_program.
what you want is this:
So what you need is your program to have the init as father and not the console.
How do you archive this. Simple. Your program should doublicate itself (create a child):
And then the father should kill himself. The child will remain orphan and his new father will be init
you duplicate a program with fork system call.
for more info.
If you write in C, in main() after you declare the variables, put this:
if ( fork())
fork will duplicate the the program, and only the father will enter in the body of if, because fork returns the pid of the child to the father > 0 and 0 to the child.
If you do this, when you execute the program, the prompt in the console will be regained immediately and the program will run in the background.