Hi All,

I am very new to C Programming. I am writing a C Program to run in an UNIX machine which is used to Archive Log files if it exceeds a particular Size.

The thing is the program has to get the details of the file like file name, file path , Threshold Size and Check time from the database.

**Each row in the database is an information about a single Log file. **

If there is ten rows, I have to make ten Fork() calls and get the value from database for each row and check the size and also if the check time is "10" mins, after 10 minutes again i have to check the size of the file.

Its like the program is to run for ever in particular intervals to check the log file size depending upon the Check time defined in table for each row.

I dont know where to start. How to make the program run all the time on a particular interval.

I just need an abstract Idea on how to do this program. Any help is much appreciated.

Thanks in advance

Recommended Answers

All 2 Replies

Your main program can poll the files in question. When they get to the requisite size you can fork()/exec() a child process which know it is a child can take the file name and then archive the file in question, terminating when that is finished. So, you could have many children running which may exceed system resources (caveat programmer!), so you need to use one of the wait() functions to be informed when a child dies so the system will not leave zombie processes hanging around.

Another approach is to use the inotify api's to monitor the directories and files in them for specific events that you can specify, which will signal you when it happens. That eliminates the polling. I used this in the past year or two writing logfile processing systems for performance engineering. The code was a mix of C and C++. We were able to process 10 billion data points per day from 5000 systems, each point representing 1 log file line.

Thanks Rubberman !!!

This is really helpfull. I think I cant use the inotify Api as i am Using AIX machine. Inotify is not there in AIX.

** Please correct me if i am wrong in understanding your suggestion.

. I have to create a table in which each row has information about a particular log file like filename, filepath, threshold size and interval time

. In my C program, I have to make an SQL statement and collect all the rows present.

. And then for each row, I have to make a fork call and create child process

. In the child process, i have to check the size of the log file and do necessary operations. **if the interval time is for ex 2 mins , then the Child has to sleep for 10 mins and again check the log file size and it contiunes for ever.

So in this way i will achieve my target, am i going in the right way...
Please clarify.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.