The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
zombie process jeenat Linux 5 03-28-2008 07:36 AM
zombie daemon process!! rish2005 UNIX for Advanced & Expert Users 1 11-25-2005 09:59 AM
Zombie process swhitney UNIX for Advanced & Expert Users 2 10-22-2004 06:12 PM
zombie program merlin UNIX for Dummies Questions & Answers 8 11-14-2002 11:31 AM
Zombie Files on a HP-UX JackieRyan26 High Level Programming 5 01-15-2002 03:20 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-09-2005
Kacyndra Kacyndra is offline
Registered User
  
 

Join Date: May 2005
Posts: 2
Question Daemon...Zombie?? Please help me

Hello,
i am very very puzzled,
im doing this project for school, its a deamon logger, but anyways
I'm supposed to run the daemon, let it run on the backgroun, and then run a different program (from command like prompt). but when i run my daemon, it never goes back to the nova> prompt.
i dont know what that means, and what i did wrong... someone please help.
Below is my code:

*Basically what it's supposed to do it look for files in a given direcotry, and append them to the Main Log File, and delete the old files. Only keeping the MainLogFile. So yea..... i got to work as a regular program, but when i tried to make into a daemon, it just freezes up, after eerything is done, not letting me run the main program.
i dont know if i'm exmplaining myself right.... but PLEASE HELP ME!!!!

----Tanya


Code:
int filedata(char *pathname, int x);
int List()
//list files in the current working directory
{
        //check if already a daemon
        if(getppid() ==1) return(0);

        //fork
        int i;
        i = fork();
        if(i<0) exit(1);        //fork error, exit
        if(i>0) exit(0);        //parent exits
        //child continues......
        setsid();       //obtain new process group

        //variable declarations
        struct dirent *d;
        char *NewDir;
        DIR *dp;
        char buffer[50];
        static int x=0;
        chdir("LogFiles");
        NewDir = getcwd(buffer, 50);
        cout << "Dir: " << NewDir << endl;
        dp = opendir(NewDir);
        while(d = readdir(dp))
        {
                if(d->d_ino != 0)
                {
                        filedata(d->d_name,x);
                        x++;
                }

        }
        closedir(dp);
        //signla handlers
        signal(SIGCHLD, SIG_IGN);       //ignore the child
        signal(SIGTSTP, SIG_IGN);       //ignore tty signals
        sigset(SIGHUP, SIG_IGN);
        sigset(SIGINT, SIG_IGN);
        sigset(SIGPOLL, SIG_IGN);
        sigset(SIGCLD, SIG_IGN);
        sigset(SIGTERM, SIG_IGN);
        return (0);
}

int filedata(char *pathname, int x)
//list file detail in the directory
{
        struct stat statbuf;
        ifstream  in;   //reading

        if(stat(pathname, &statbuf) == -1)
        {
                cout << "could not stat " << pathname << endl;
                return (-1);
        }
        cout << pathname << endl;
        string Msg, ToFileFinal;
        string ToFile;
        if(x <2)
        {
                cout << ". and .. right now...." << endl;
        }
        else
        {
                cout << "FileName: " << pathname << endl;
                //read from a file
                in.open(pathname);
                getline(in, ToFile);
                getline(in,Msg);
                cout << "ToFile: " << ToFile << endl;
                cout << "Message: " << Msg << endl;
                //write to a file
                ToFileFinal = "../";
                ToFileFinal.append(ToFile);
                cout << "the output will be written to: " << ToFileFina
                cout << endl;
                ofstream out;
                out.open(ToFileFinal.c_str(), ios::app);
                out << Msg;
                out << endl;
                out << "*** | *** | *** | *** | *** | ***" << endl;
                //close the files before leaving
                in.close();
                out.close();
                //delete the input files
                cout << "about to remove..." << pathname << endl;
                remove(pathname);
                wait(30);
        }
        return (statbuf.st_mode);

}

int main()
{
                List();
                while(1) sleep(1);//run
                return (0);
}


Last edited by Perderabo; 05-09-2005 at 09:48 PM.. Reason: Add code tags for readability
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0