Sponsored Content
Top Forums UNIX for Advanced & Expert Users Needs help in launching a console application with the help of daemon process Post 302484805 by gopallinux on Monday 3rd of January 2011 09:49:15 AM
Old 01-03-2011
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:
Code:
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
Code:
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

Last edited by vbe; 01-03-2011 at 01:12 PM.. Reason: code tags
 

7 More Discussions You Might Find Interesting

1. Programming

Daemon process

Hi, I have to write a daemon process, which performs certain operations in the background. Now since it performs operations in the background, it should not display anything to the standard output. The problem is that it still displays, text on standard output. Can anyone tell me (it is... (2 Replies)
Discussion started by: s_chordia
2 Replies

2. Programming

What is a daemon process?

This is gonna seem really silly to almost evryone here - but I need to know : what is a daemon process? Thanks (6 Replies)
Discussion started by: Kanu77
6 Replies

3. Linux

daemon process

how i will write the daemon process,if any body have sample daemon process send me. (1 Reply)
Discussion started by: suresh_rupineni
1 Replies

4. Red Hat

Problem launching process as BG with &

After i launch the process as back ground, when I try to grab the shell by sending the enter, process is going to Stopped state. How do I successfully run the job in bg with &. Thanks in Advance (1 Reply)
Discussion started by: hansini
1 Replies

5. Programming

Show progress in console application

Hi all I have a program in C++ that I compiled on Ubuntu 9.0 and Centos 5, after I got it running on Windows. In this program, I show progress of a process using the following construct: i = 0; quantum = floor(total_iterations, 100); perc = 0; do { remain = fmod(i, quantum); ... (3 Replies)
Discussion started by: msaqib
3 Replies

6. UNIX for Advanced & Expert Users

Launching a process in remote machine

Hi all, Normally to launch a process in the remote machine I will use ssh to the machine and launch the process.I want to launch the remote machine process with out login into the machine . Is there any way. It may be any workaround method. Thanks in advance .:) (3 Replies)
Discussion started by: karthigayan
3 Replies

7. Programming

Daemon process

I wish to make a process run in the background, but only one instance of it, and not many, so when the program is loaded, it has to check whether another instance of the same program is running and if so to exit. How do I do this ? (4 Replies)
Discussion started by: sundaresh
4 Replies
DAEMON(3)						   BSD Library Functions Manual 						 DAEMON(3)

NAME
daemon -- run in the background LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdlib.h> int daemon(int nochdir, int noclose); DESCRIPTION
The daemon() function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons. On Mac OS X, the use of this API is discouraged in favor of using launchd(8). Unless the argument nochdir is non-zero, daemon() changes the current working directory to the root (/). Unless the argument noclose is non-zero, daemon() will redirect standard input, standard output, and standard error to /dev/null. RETURN VALUES
The daemon() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The daemon() function may fail and set errno for any of the errors specified for the library functions fork(2) and setsid(2). SEE ALSO
fork(2), setsid(2), sigaction(2) HISTORY
The daemon() function first appeared in 4.4BSD. CAVEATS
Unless the noclose argument is non-zero, daemon() will close the first three file descriptors and redirect them to /dev/null. Normally, these correspond to standard input, standard output, and standard error. However, if any of those file descriptors refer to something else, they will still be closed, resulting in incorrect behavior of the calling program. This can happen if any of standard input, standard out- put, or standard error have been closed before the program was run. Programs using daemon() should therefore either call daemon() before opening any files or sockets, or verify that any file descriptors obtained have values greater than 2. The daemon() function temporarily ignores SIGHUP while calling setsid(2) to prevent a parent session group leader's calls to fork(2) and then _exit(2) from prematurely terminating the child process. BSD
June 9, 1993 BSD
All times are GMT -4. The time now is 09:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy