![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 3
Rep Power: 0
![]() |
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); |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Which Unix system are you using?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 3
Rep Power: 0
![]() |
SunOS
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|