Sponsored Content
Top Forums Programming Daemon...Zombie?? Please help me Post 71287 by Kacyndra on Monday 9th of May 2005 05:38:52 PM
Old 05-09-2005
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. Smilie
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. Smilie
i dont know if i'm exmplaining myself right.... but PLEASE HELP ME!!!!

----Tanya Smilie

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
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

zombie program

When you run a ps -ef and if the status is a Z (zombie) does that mean the same as not responding? (Like a windows machine). Also has anyone here heard of the program called 'top' (I've found it on our Solaris 7 machines) If you have you might be able to help me. I need to know if there is a... (8 Replies)
Discussion started by: merlin
8 Replies

2. UNIX for Advanced & Expert Users

Zombie process

I would like to create a zombie process so that I can test monitoring software functionality. Any techniques? (2 Replies)
Discussion started by: swhitney
2 Replies

3. UNIX for Advanced & Expert Users

zombie daemon process!!

My daemon process is the child of init and init has the responsibility to remove it, once it turns zombie. But I want to ask why the daemon process which is child of init turns zombie in the first place. What measures I have to take to avoid this? rish (1 Reply)
Discussion started by: rish2005
1 Replies

4. Shell Programming and Scripting

Zombie process

Hi I need help because I don't know if it is possible to add a find inside a cat. like I have a file with the pid of the process that use to became zombie. And I have the same pid stored in the var (pid1) now, I have no clue how to check if the the find finds the pid or even if it's... (2 Replies)
Discussion started by: ruben.rodrigues
2 Replies

5. Solaris

zombie process

dear friends, in an interview they asked me what is zombie process. how we can identifying these process.if can you kill all zombie process. (8 Replies)
Discussion started by: sijocg
8 Replies

6. AIX

zombie process

Is there an equivilant to the preap command in AIX that would allow me to get rid of a zombie process. I am new to AIX, moving over from Solaris and in the past I have been able to preap the pid on the defunct process to clean them up. I have looked around and the best I can see is that it may... (3 Replies)
Discussion started by: sboots
3 Replies

7. UNIX for Dummies Questions & Answers

what is zombie , how to kill it ,

Hello I try to googled it , but I dint get sufficient answer :( .. When I can see zombie running on server do they consume system resources or not ? I have read that is not good to kill them with signal 9 cause it might cause more troubles .. why is kill -9 so harmfull? thanks (2 Replies)
Discussion started by: kvok
2 Replies

8. UNIX for Advanced & Expert Users

Zombie process

What is the overhead associated with zombie process?Is it running out of process-ID?:confused: Since some information is stored in process table.. Thanks in Advance (4 Replies)
Discussion started by: jois
4 Replies

9. Red Hat

zombie

Hi, Linux redhat 5.5 top shows that i have 20 zombie process : Tasks: 357 total, 1 running, 336 sleeping, 0 stopped, 20 zombie Cpu(s): 0.2%us, 0.3%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 24949400k total, 2363052k used, 22586348k free, 227084k buffers... (1 Reply)
Discussion started by: yoavbe
1 Replies

10. Programming

Zombie in C

hello all, when we are creating a process by using fork, if the child process terminates before parent, the child process exists as zombie.. My doubt is when that child process terminates, how come that process exists further and show as a zombie process..can anyone help me to clear about this? (1 Reply)
Discussion started by: aarathy
1 Replies
All times are GMT -4. The time now is 12:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy