webcam server question - Slackware

This is a discussion on webcam server question - Slackware ; I have a webcam server set up on my slackware 10.2 system. I start the webcam server by typing in a telnet window: >webcam_server -d /dev/video1 The server works great but I have two problems. 1. The telnet window is ...

+ Reply to Thread
Results 1 to 11 of 11

Thread: webcam server question

  1. webcam server question

    I have a webcam server set up on my slackware 10.2 system. I start the
    webcam server by typing in a telnet window: >webcam_server -d /dev/video1

    The server works great but I have two problems.
    1. The telnet window is no longer usable unless I stop the server by
    typing in CTRL-C keys.
    2. I want to be able to start and stop the webcam_server program like a
    normal service at will.

    How do I start the server as a service and then how can I stop it later?

    I noticed that some examples show the use of a service command. I don't
    seem to have a program called service on my system.

    Please help, Thanks

  2. Re: webcam server question

    George wrote:
    > I have a webcam server set up on my slackware 10.2 system. I start the
    > webcam server by typing in a telnet window: >webcam_server -d /dev/video1
    >
    > The server works great but I have two problems.
    > 1. The telnet window is no longer usable unless I stop the server by
    > typing in CTRL-C keys.
    > 2. I want to be able to start and stop the webcam_server program like a
    > normal service at will.
    >
    > How do I start the server as a service and then how can I stop it later?
    >
    > I noticed that some examples show the use of a service command. I don't
    > seem to have a program called service on my system.
    >
    > Please help, Thanks



    Nevermind--- I found the answers:
    Start: exec name_of_file
    Stop: killall -9 name_of_file

    seems to do the job

  3. Re: webcam server question

    George wrote:
    >> The server works great but I have two problems. 1. The telnet window is
    >> no longer usable unless I stop the server by typing in CTRL-C keys.
    >> 2. I want to be able to start and stop the webcam_server program like a
    >> normal service at will.


    > Nevermind--- I found the answers:
    > Start: exec name_of_file
    > Stop: killall -9 name_of_file
    >
    > seems to do the job


    Doing "exec name_of_program" will cause the current shell to exit when the
    program is done. It will not give you your prompt back, so I don't
    know if this is the best solution to problem 1. One way would be to send
    the program to the background by starting it like this:

    name_of_program &

    Or, in your case:

    webcam_server -d /dev/video1 &

    Not all programs can be sent to the background like that, if they want to
    keep the terminal for input they will be supended.

    As you already found out, killall is useful also to stop programs running
    in the background.

    regards Henrik
    --
    The address in the header is only to prevent spam. My real address is:
    hc1(at)poolhem.se Examples of addresses which go to spammers:
    root@localhost postmaster@localhost


  4. Re: webcam server question

    Henrik Carlqvist wrote:
    > George wrote:
    >>> The server works great but I have two problems. 1. The telnet window is
    >>> no longer usable unless I stop the server by typing in CTRL-C keys.
    >>> 2. I want to be able to start and stop the webcam_server program like a
    >>> normal service at will.

    >
    >> Nevermind--- I found the answers:
    >> Start: exec name_of_file
    >> Stop: killall -9 name_of_file
    >>
    >> seems to do the job

    >
    > Doing "exec name_of_program" will cause the current shell to exit when the
    > program is done. It will not give you your prompt back, so I don't
    > know if this is the best solution to problem 1. One way would be to send
    > the program to the background by starting it like this:
    >
    > name_of_program &
    >
    > Or, in your case:
    >
    > webcam_server -d /dev/video1 &
    >
    > Not all programs can be sent to the background like that, if they want to
    > keep the terminal for input they will be supended.
    >
    > As you already found out, killall is useful also to stop programs running
    > in the background.
    >
    > regards Henrik

    Thanks for the help,
    I have another question: Do you know what the syntax would be to put the
    [webcam_server -d /dev/video1 &] call into a system() function in a
    perl script? I would like to be able to make this call through a CGI
    interface from the web. The other problem is that to kill the process
    seems to require ROOT access. So I don't know how to allow the CGI code
    to be allowed to access the killall function. I made a perl script that
    works from the terminal prompt as root but wont allow access through Web
    CGI or as a normal user at the terminal.

  5. Re: webcam server question

    George wrote:
    > I have another question: Do you know what the syntax would be to put the
    > [webcam_server -d /dev/video1 &] call into a system() function in a
    > perl script?


    Sorry, I am not very good a perl programming. However, if you know how to
    call a program without sending it to the background in perl, maybe you can
    use that knowledge combined with a shell script that sends the program to
    the background?

    In C I would probably do it something like this:

    if (! fork() )
    system("webcam_server -d /dev/video1");

    Or, with the shell-script solution instead of fork:

    system("my_script.sh");

    Where my_script.sh would look something like this:

    -8<--------------------------------
    #!/bin/bash

    webcam_server -d /dev/video1 &
    -8<--------------------------------

    > I would like to be able to make this call through a CGI
    > interface from the web.


    For a web solution I would prefer some php code, maybe in combination with
    a script like the one above.

    > The other problem is that to kill the process
    > seems to require ROOT access.


    Usually the user that started a process is also able to kill the process.
    However, if the program has the setuid bit set root becomes owner of the
    process. To kill such a process without being root you will need to
    configure sudo.

    regards Henrik
    --
    The address in the header is only to prevent spam. My real address is:
    hc1(at)poolhem.se Examples of addresses which go to spammers:
    root@localhost postmaster@localhost


  6. Re: webcam server question

    Henrik Carlqvist wrote:
    > George wrote:
    >> I have another question: Do you know what the syntax would be to put the
    >> [webcam_server -d /dev/video1 &] call into a system() function in a
    >> perl script?

    >
    > Sorry, I am not very good a perl programming. However, if you know how to
    > call a program without sending it to the background in perl, maybe you can
    > use that knowledge combined with a shell script that sends the program to
    > the background?
    >
    > In C I would probably do it something like this:
    >
    > if (! fork() )
    > system("webcam_server -d /dev/video1");
    >
    > Or, with the shell-script solution instead of fork:
    >
    > system("my_script.sh");
    >
    > Where my_script.sh would look something like this:
    >
    > -8<--------------------------------
    > #!/bin/bash
    >
    > webcam_server -d /dev/video1 &
    > -8<--------------------------------
    >
    >> I would like to be able to make this call through a CGI
    >> interface from the web.

    >
    > For a web solution I would prefer some php code, maybe in combination with
    > a script like the one above.
    >
    >> The other problem is that to kill the process
    >> seems to require ROOT access.

    >
    > Usually the user that started a process is also able to kill the process.
    > However, if the program has the setuid bit set root becomes owner of the
    > process. To kill such a process without being root you will need to
    > configure sudo.
    >
    > regards Henrik

    Thanks, this is very helpful, I will try this tonight.

  7. Re: webcam server question

    I tried everything, but can't seem to get it to work correctly. I can
    start the process OK but then my web page hangs forever or until I kill
    the process.

    I tried using code in a perl script, 'C' program, and in a .sh script in
    all cases the process will not release the process that started it.

    Here are the things that I tried:

    1. C program,
    if(!fork())
    system("/usr/local/bin/webcam_server -d /dev/video1");

    2. .sh script
    #!/bin/bash
    echo "starting webcam"
    /usr/local/bin/webcam_server -d /dev/video1 &

    3. Perl script
    system("/usr/local/bin/webcam_server -d /dev/video1 &");

    In all three cases is used the same perl CGI script system() call to
    access the different methods that I tried. In every case the web page
    hung until I killed the process.

    Is there any way to start a process without hanging the parent process?
    These methods work fine if I run them from a prompt just not from a cgi
    call.

    Thanks for any help.


    Henrik Carlqvist wrote:
    > George wrote:
    >> I have another question: Do you know what the syntax would be to put the
    >> [webcam_server -d /dev/video1 &] call into a system() function in a
    >> perl script?

    >
    > Sorry, I am not very good a perl programming. However, if you know how to
    > call a program without sending it to the background in perl, maybe you can
    > use that knowledge combined with a shell script that sends the program to
    > the background?
    >
    > In C I would probably do it something like this:
    >
    > if (! fork() )
    > system("webcam_server -d /dev/video1");
    >
    > Or, with the shell-script solution instead of fork:
    >
    > system("my_script.sh");
    >
    > Where my_script.sh would look something like this:
    >
    > -8<--------------------------------
    > #!/bin/bash
    >
    > webcam_server -d /dev/video1 &
    > -8<--------------------------------
    >
    >> I would like to be able to make this call through a CGI
    >> interface from the web.

    >
    > For a web solution I would prefer some php code, maybe in combination with
    > a script like the one above.
    >
    >> The other problem is that to kill the process
    >> seems to require ROOT access.

    >
    > Usually the user that started a process is also able to kill the process.
    > However, if the program has the setuid bit set root becomes owner of the
    > process. To kill such a process without being root you will need to
    > configure sudo.
    >
    > regards Henrik


  8. Re: webcam server question

    George wrote:
    > I tried everything, but can't seem to get it to work correctly. I can
    > start the process OK but then my web page hangs forever or until I kill
    > the process.
    >
    > I tried using code in a perl script, 'C' program, and in a .sh script in
    > all cases the process will not release the process that started it.


    I think you want a daemon. Here's a simple example that spawns a
    useless process and completely detaches it from the host shell. Use
    killall or the process id to kill it.

    ----- test.c -----
    #include

    int main(int argc, char **argv)
    {
    daemon(0, 0);

    while(1) { usleep(1); }
    }
    -----
    > gcc -o test test.c
    > ./test
    > killall ./test



    You might modify this by replacing the while loop with a call to exec
    your webcam server. Note that daemon(0,0) changes the working directory
    to root ("/").

    Search for "daemon programming" to get more useful info. In particular,
    wikipedia has some links you might appreciate.
    http://en.wikipedia.org/wiki/Daemon_...er_software%29

    - Daniel

  9. Re: webcam server question

    George wrote:
    > Is there any way to start a process without hanging the parent process?


    This is a bit odd to me. When the new process is created it becomes a
    child process. The process that did the call to fork becomes the parent
    process.

    If the child process exits first it will become a zombie process until the
    parent process does a call to wait or until also the parent process dies.

    If the parent process exits first (which should be what happens in your
    case) the child process becomes orphaned and gets the init process with
    pid 1 as its parent process.

    In teory there should be no problem to exit a program even though it has
    spawned off child processes. However, I have seen at least one such case
    as the one you are now describing.

    On a RedHat machine a startup script started a daemon by calling a program
    something like this:

    the_program &

    This startup script worked fine during boot, but redhat also had a
    graphical tool to run and restart startup scripts. When using that tool to
    run or restart the script the tool hanged until the daemon process was
    killed. I never found out why, but resorted to placing the daemon startup
    in an rc.local file instead which wasn't used by that tool.

    In the case of the startup script I never tried to use nohup, but maybe it
    would have helped and maybe it would help also for you. Something like
    this:

    system("nohup /usr/local/bin/webcam_server -d /dev/video1 &");

    regards Henrik
    --
    The address in the header is only to prevent spam. My real address is:
    hc1(at)poolhem.se Examples of addresses which go to spammers:
    root@localhost postmaster@localhost


  10. Re: webcam server question

    George wrote:

    > 2. .sh script
    > #!/bin/bash
    > echo "starting webcam"
    > /usr/local/bin/webcam_server -d /dev/video1 &


    I did suggest to try nohup, but with another shell nohup might not be
    necessary:

    #!/bin/tcsh
    echo "starting webcam"
    /usr/local/bin/webcam_server -d /dev/video1 &

    regards Henrik
    --
    The address in the header is only to prevent spam. My real address is:
    hc1(at)poolhem.se Examples of addresses which go to spammers:
    root@localhost postmaster@localhost


  11. Re: webcam server question

    That worked!!

    I used the following lines in my 'C' program and that seemed to do what
    I needed:

    if(!fork())
    {
    daemon(0, 0);
    system("/usr/local/bin/webcam_server -d /dev/video1 &");
    }

    The pstree result does not show any orphaned programs and the webcam
    server is running.

    Thanks !!!!

    D Herring wrote:
    > George wrote:
    >> I tried everything, but can't seem to get it to work correctly. I can
    >> start the process OK but then my web page hangs forever or until I
    >> kill the process.
    >>
    >> I tried using code in a perl script, 'C' program, and in a .sh script
    >> in all cases the process will not release the process that started it.

    >
    > I think you want a daemon. Here's a simple example that spawns a
    > useless process and completely detaches it from the host shell. Use
    > killall or the process id to kill it.
    >
    > ----- test.c -----
    > #include
    >
    > int main(int argc, char **argv)
    > {
    > daemon(0, 0);
    >
    > while(1) { usleep(1); }
    > }
    > -----
    > > gcc -o test test.c
    > > ./test
    > > killall ./test

    >
    >
    > You might modify this by replacing the while loop with a call to exec
    > your webcam server. Note that daemon(0,0) changes the working directory
    > to root ("/").
    >
    > Search for "daemon programming" to get more useful info. In particular,
    > wikipedia has some links you might appreciate.
    > http://en.wikipedia.org/wiki/Daemon_...er_software%29
    >
    > - Daniel


+ Reply to Thread