Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 16th, 2006, 4:17 PM   #1
dionys
Newbie
 
Join Date: Mar 2006
Posts: 3
Rep Power: 0 dionys is on a distinguished road
How to make a daemon ( Jop Dispatcher )

Hello Guys...

I'm new to operating systems and i have a little experience with Unix enviroments.
I must make a job dispatcher (daemon ) under Unix.
I have posted the problem because i want specific guidelines.I dont know how to start.
Do you have any useful links or tutorials to help me solve this problem?

My daemon must handle to things:

1. a directory(job_in_dir)
2. a named pipe(jobd_fifo)
TASK1
-------
The daemon checks periodically (POLL_JOP_INTERVAL) a directory(jobd_in_dir) for new scripts.If the daemon find a script,then it will execute it and it will place the output of the script in a file(the file has the unique number of the script) in a second directory (jobd_out_dir).

TASK2
--------
After the daemon is initialized must create a new named pipe,that will check periodically(POLL_CMD_INTERVAL) for new messages
e.g
input:x (x=1,2,3.... , x:script number)
output: the output of the script

/* jobd API */

/* Constants.  */
const char *jobd_fifo = "/home/elathan/uoc/345/1/comm";
const char *jobd_in_dir = "/home/elathan/uoc/345/1/jobs/";
const char *jobd_out_dir = "/home/elathan/uoc/345/1/out/";
const char *jobd_main_dir = "/home/elathan/uoc/345/1/";

#define POLL_JOB_INTERVAL   10  /* Poll for waiting jobs every 10 secs.  */
#define POLL_CMD_INTERVAL   5   /* Poll for status cmds every 5 secs.    */   
        
#define JOBD_PREFIX "jobd__out__"
#define JOBD_QUEUE_MAX 500

/*  
    Initialization routine. Create needed directories if they don't
    exist, establish any needed signal handlers, establish the named pipe for
    external communication and call jobd_daemonize() to become a
    daemon.  
*/
void jobd_init(void);

/*
    Clean up and exit. You should remove everything done in
    jobd_out_dir.
*/
void jobd_finalize(void);

/*
    Become a daemon.
*/
int jobd_daemonize(void);             

/* 
    Signal handler, which should be invoked every
    POLL_JOB_INTERVAL seconds. It should call jobd_check_dir()
    in jobd_in_dir to check for available jobs.
*/
void jobd_dispatcher(int sig);        

/* 
    Check a directory for available jobs (scripts). If a script
    is found, call jobd_dispatch to execute the script.
*/
void jobd_dir_check(const char *dir); 

/*
    Dispatch a job (script). Build a command string which should
    execute the script and redirect the output to a unique file
    in jobd_out_dir. Use system() to execute the command string.
    After a correct execution, you should delete the original
    script from jobd_in_dir.
*/
int jobd_dispatch(char *jobname);     

/*
    Handle an incoming message from jobd_fifo. This function should
    be called every POLL_CMD_INTERVAL.
*/
void jobd_handle_msg(char *msg);
dionys is offline   Reply With Quote
Old Mar 16th, 2006, 4:35 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Which Unix system are you using?
Arevos is offline   Reply With Quote
Old Mar 16th, 2006, 4:37 PM   #3
dionys
Newbie
 
Join Date: Mar 2006
Posts: 3
Rep Power: 0 dionys is on a distinguished road
SunOS
dionys is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC