-3

I have to run a C program using monit. so I had to demonize it. what i did was i took a daemon template made some changes and arrived at this file as below, which is a script file:

# Source function library
. /home/stallions/queue.c

# Do preliminary checks here, if any
#### START of preliminary checks #########


##### END of preliminary checks #######

# Handle manual control parameters like start, stop, status, restart, etc.

case "$1" in
  start)
    # Start daemons.

    echo -n $"Starting queue daemon: "
    echo
    daemon queue
    echo
    ;;

  stop)
    # Stop daemons.
    echo -n $"Shutting down queue: "
    killproc queue
    echo

    # Do clean-up works here like removing pid files from /var/run, etc.
    ;;
  status)
    status queue

    ;;
  restart)
    $0 stop
    $0 start
    ;;

  *)
    echo $"Usage: $0 {start|stop|status|restart}"
    exit 1
esac

exit 0

when i execute this file # ./queue i get errors

         # line 8: 'void fifoinit(int size)'
         # line 8: syntax error near unexpected token

I am not sure what should be the source function library path. I have given it the path where my original queue.c exits which i wanted to run it as a daemon. Can you ell me should there be anything else to be done to run this as a daemon and how to correct the errors?

17
  • 1
    You obviously don't have a bit of a clue what you are doing. .c files have to be compiled, they can't be sourced into a bash script.
    – Sven
    May 7, 2012 at 14:25
  • I actually have to run them using monit...so when i asked it yesterday here all replied that i have to demonize it so that i could run it. so thats what I did....so how do i run them using monit then? May 7, 2012 at 14:27
  • You have to learn so much I don't even know where to begin with. You write a program in C, compile it and then you can use a script like the one you copied here to demonize it, or you can let the C program handle that itself and you use this script to start/stop the demon. This is all way off-topic here.
    – Sven
    May 7, 2012 at 14:30
  • I am sorry if its off topic, but i really need to know i have a project deadline tomorrow. I will tell you what I did clearly. May 7, 2012 at 14:32
  • 3
    Then you are not qualified for this project and should hand it over to someone who is. I am sorry, but you are lacking so much that we just can't fix this on a site like Server Fault.
    – Sven
    May 7, 2012 at 14:33

1 Answer 1

3

You need first to compile your C program. The following command can do it if your program does not depend on any library to be linked with:

$ gcc -o queue queue.c

This will produce the binary queue if it goes well. It seems your script is trying to execute this binary. You need just to make sure to set the correct path.

Don't source the C program into your shell script. Remove the line:

. /home/stallions/queue.c
7
  • I have compiled it and got the file: a.out Where shold i set the path in the script file of queue May 7, 2012 at 14:42
  • You need to rename it using mv a.out /some/path/queue. Choose a valid path for /some/path. Then, use the same path in your shell script.
    – Khaled
    May 7, 2012 at 14:44
  • I did what you said and now i got the binary file also. I gave the path of this binary in the script. when i run the script it says cannot execute binary file May 7, 2012 at 15:11
  • Did you bother to set the execute flag on the binary with chmod?
    – growse
    May 7, 2012 at 15:13
  • chmod 755 queue? May 7, 2012 at 15:15

Not the answer you're looking for? Browse other questions tagged .