ipc - c daemon runtime shell parameters -


i'd develop daemon can controlled means of shell commands. clarify let's daemon have 3 functions (the invoke i'd have):

$ mydaemon start #do nothing, daemonize. exit(0) success, exit(1) otherwise

$ mydaemon stop #ask daemon stop. exit(0) success, exit(1) otherwise

$ mydaemon dosomething #ask daemon. exit(0) success, exit(1) otherwise (let's daemon int = 0; exit(0); see code, not interested in special stuffs)

may kindly show me example on how produce daemon (ok, start simple...)?

thanks all!

if want daemon work, 1 way write terminal program pass commands terminal daemon via ipc technique.

all have is:

  • write terminal program forks , execl daemon along command line arguments( file descriptors if using pipes).
  • the terminal program takes input in while loop terminal , passes them daemon through ipc mechanism in use.

edit

algorithm main process

main() {     > fork daemon initial arguments(if any)     while(1)     {         > take inputs shell         > parse input , pass daemon(via preferred mechanism)         > if(exit condition) kill->daemon , break     } } 

for daemon

main() (or function_name() if no execl) {     > initialize arguments , ipc mechanism     while(1)     {         > read command(can use simple integer/character commands)         > perform requested action or break if exit command     }     > proper exit(closing file descriptors,etc.) } 

Comments