Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 daemons.

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

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

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

    $0 stop
    $0 start

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

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?


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 Sven, 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.

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 '12 at 14:25
I actually have to run them using when i asked it yesterday here all replied that i have to demonize it so that i could run it. so thats what I 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. – Sven 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
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 '12 at 14:33

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

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