Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share

locked by Iain May 7 '12 at 15:34

This post has been locked due to the high amount of off-topic comments generated. For extended discussions, please use chat.

closed as too localized by SvW, ewwhite, Tom O'Connor, Iain May 7 '12 at 14:43

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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. –  SvW May 7 '12 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? –  balu May 7 '12 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. –  SvW May 7 '12 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. –  balu May 7 '12 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. –  SvW May 7 '12 at 14:33
show 12 more comments

1 Answer

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
share
    
I have compiled it and got the file: a.out Where shold i set the path in the script file of queue –  balu May 7 '12 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 '12 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 –  balu May 7 '12 at 15:11
    
Did you bother to set the execute flag on the binary with chmod? –  growse May 7 '12 at 15:13
    
chmod 755 queue? –  balu May 7 '12 at 15:15
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.