Needs help in launching a console application with the help of daemon process

Hi All,

I am facing problem in launching a application with the help of a daemon process. Actually the application is based on command line that reads various commands for controlling the application from the console and accordingly executes those commands. The application always interact with console and try to read the command in while loop such as:

std::getline(std::cin, cmd); 
if(std::cin.fail()) 
{  
 //stop the reading and execution of application
} 

In daemon program that launches the application as a child process, after forking and in child process, after setting sid and chdir, we close the descriptor like

close(STDOUT_FILENO);
close(STDERR_FILENO);

but does not closing the STDIN_FILENO so that the application can read the command from STDIN_FILENO. Daemon process does fork and execv the application so that application can run as a child of daemon process. On Linux, this daemon program for running the application as a child process is working fine. Daemon program runs the application successfully on Linux platform and runs as per the expectation.
But when running the daemon program from windows with the help of plink (for executing the daemon process on Linux platform from window), plink executes the daemon and the daemon process executes the application on Linux but just after 1-2 seconds, application and daemon both stop their execution and child of the application run as a daemon process. Except the child of application, rest all other process like main daemon program, application are stopping the execution. Could you please suggest me what is causing the problem and why from windows (with the help of plink) daemon process and the application is not running as expected on Linux.
Anyone with knowledge of how to get rid of these would be greatly appreciated.
Thanks

Perhaps the application is expecting there to be a stdout/stderr file descriptor - instead of the close you could try:

int fd=open("/dev/null",O_WRONLY);
if(fd >=0) {
    dup2(fd,STDOUT_FILENO);
    dup2(fd,STDERR_FILENO);
    close(fd);
}

Obviously on Linux you want to open "/dev/null", but I guess on windows that would be "nul"...

Thanks for the suggestion, I have already tried this but fail to run the application on Linux machine with plink from windows machine.
As I explained above, there is no problem in running daemon and application (child of daemon) on Linux machine. Problem is there when I am trying to run the daemon on Linux machine from windows machine(remote machine) with plink. I mean on windows command prompt executing the following command:
plink -ssh -pw <password> <machine IP>:/ "path"; ./daemon

This command will establish the connection with Linux machine and will execute daemon process present in the given path. This command is launching the daemon process on Linux machine but after 1-2 sec, daemon is stopping the execution. I am not able to find out the reason that causing the problem

Perhaps you could try using "strace", eg:

plink -ssh -pw <password> <machine IP>:/ "path"; strace -s 8192 -v -f -o /tmp/trace.log ./daemon

strace should give you an idea of what may be going wrong (logged into /tmp/trace.log)