Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Managing instances of a program ? daemon ?

    Hi ! I finished a program that connects to a remote server and does some stuff there for a while. What I want to do is to run several instances of the program to have different connections at the same time, and to be able to manage those processes automatically (for example, if the connection stops, detect it and reconect).

    I guess I will have to use the pid of the processes and handle them somehow but I dont really know what to do because I haven't used c++ in a while and I never went that deep.

    All this will be running in suse, debian and/or yellowdog distros Maybe there's a tutorial or you guys know some tool that i can use, any info will be helpful !! Last time I posted you helped me a lot and i learnt very much about c++ so thanks in advance
    Last edited by SingleFemaleLawyer; 03-24-2011 at 11:40 AM. Reason: new title

  2. #2
    I'm thinking I need to code a daemon that creates several instances of the connection program and monitors them Should I create child processes ?

  3. #3
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris

    Whenever I come across a requirement for simultaneous processes, I think of GNU parallel: GNU Parallel - GNU Project - Free Software Foundation

    When I see requirements for remote connections, lately I think of:
           pdsh - issue commands to groups of hosts in parallel
    I think I'm better off if I can I keep all that machinery out of my code simply because I think that someone who's specializing in that probably did it better than I could.

    For example, I have a script that keeps track of uptimes:
    #!/usr/bin/env bash
    # @(#) my-uptimes	Run vertime on many remote hosts.
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    pe() { for i;do printf "%s" "$i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for i;do printf "%s" "$i";done; printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && . $C pdsh
    # Get local uptime, then remotes.
    pl " Uptimes for available machines:"
    pdsh -N -R exec -w - ssh %h bin/vertime 2>/dev/null <<'EOF'
    exit 0
    which produces:
    $ ./my-uptimes 
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.7 (lenny) 
    GNU bash 3.2.39
    pdsh-2.16 (+debug)
     Uptimes for available machines:
    up 66 days, 18 users: Debian GNU/Linux 5.0.7 (lenny) on AMD Athlon(tm) 64 Processor 3000+
    up 2 days,  6 users: Debian GNU/Linux wheezy/sid on Intel(R) Xeon(TM) CPU 2.80GHz
    up 21 days,  7 users: CentOS release 5.5 (Final) on Intel(R) Xeon(TM) CPU 2.80GHz
    up 18 days,  6 users: Fedora 14 (Laughlin) on Intel(R) Xeon(TM) CPU 2.80GHz
    up 18 days,  6 users: Ubuntu 10.04.2 LTS (lucid) on Intel(R) Xeon(TM) CPU 2.80GHz
    up 19 days,  6 users: Debian GNU/Linux 6.0 on Intel(R) Xeon(TM) CPU 2.80GHz
    up 18 days 14:44,  7 users: openSUSE 11.3 (Teal) on Intel(R) Xeon(TM) CPU 2.80GHz
    The FreeBSD VM was not up, so it timed out after 10 seconds.

    Of course , if you need to do the code for the connections, and / or you cannot have the code on the remotes, then this of little value to you.

    The pdsh utility was in the repositories for recent SuSE, Fedora, Debian.

    Good luck ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. $spacer_open
  5. #4
    Hi ! Thank you drl for your post it looks like a great tool but unfortunately I can't use it because I need to use a more elaborated code involving sockets, coding, and more.

    I started with
    Linux Daemon Writing HOWTO
    And I took a look at :
    Unix Daemon Server Programming

    Stil have some questions like ... when I create a child process do I need to create one for each connection like if they where threads ?
    and how do I manage the connections so that they are independent from each other and they are executed in different places of the memory ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts