Using signals as a event driven framework

Discussion in 'C Programming' started by jose luis fernandez diaz, May 3, 2004.

  1. Hi,

    I have a C program running in background in UNIX. From a shell script
    I want to notify it some events. The easiest way to do it is through
    signals, but it is not correct because signal are not a event drivent
    framework. Can anyone give me other straightforward solution ?

    Thanks,
    Jose Luis.
     
    jose luis fernandez diaz, May 3, 2004
    #1
    1. Advertising

  2. On Mon, 03 May 2004 02:37:03 -0700, jose luis fernandez diaz wrote:

    > Hi,
    >
    > I have a C program running in background in UNIX. From a shell script
    > I want to notify it some events. The easiest way to do it is through
    > signals, but it is not correct because signal are not a event drivent
    > framework. Can anyone give me other straightforward solution ?

    Signals can du fine, and you can very well make it event driven.
    However signals have ofcourse limitations, you can only use a few of them,
    and it's hard to pass additional data.
    A common approach is to use unix sockets, see e.g. and create a little
    utility that can communicate to the "server" for use in e.g. shell
    scripts.
    see e.g. http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html

    --
    Nils Olav Selåsdal
    System Engineer
    w w w . u t e l s y s t e m s . c o m
     
    =?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=, May 3, 2004
    #2
    1. Advertising

  3. ANother simple approach I use to signal programs running
    is to have a directory /me/SIGNALS
    Withing that directory I put files(empty) by a particular name.
    The running program does an open dir on every loop and check for the
    existance of files by name ?*. If this file exists, I unlink it and
    continue as if I had caught a signal.

    Very simple and limited. But you can signal a program with ANY file
    name. Not just the signals supplied by your system.

    jose luis fernandez diaz wrote:
    > Hi,
    >
    > I have a C program running in background in UNIX. From a shell script
    > I want to notify it some events. The easiest way to do it is through
    > signals, but it is not correct because signal are not a event drivent
    > framework. Can anyone give me other straightforward solution ?
    >
    > Thanks,
    > Jose Luis.



    --
    ___ _ ____ ___ __ __
    / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
    / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
    /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
    /___/
    Texas Instruments ASIC Circuit Design Methodlogy Group
    Dallas, Texas, 214-480-4455,
     
    Billy N. Patton, May 3, 2004
    #3
  4. This solution forces to write a C client program. In this case a
    prefer to use a CORBA communication framework. Anyway, is there
    another way to comunicate directly from the shell to a background
    proccess without a client program ?

    Thanks,
    Jose Luis.

    Nils O. Selåsdal <> wrote in message news:<>...
    > On Mon, 03 May 2004 02:37:03 -0700, jose luis fernandez diaz wrote:
    >
    > > Hi,
    > >
    > > I have a C program running in background in UNIX. From a shell script
    > > I want to notify it some events. The easiest way to do it is through
    > > signals, but it is not correct because signal are not a event drivent
    > > framework. Can anyone give me other straightforward solution ?

    > Signals can du fine, and you can very well make it event driven.
    > However signals have ofcourse limitations, you can only use a few of them,
    > and it's hard to pass additional data.
    > A common approach is to use unix sockets, see e.g. and create a little
    > utility that can communicate to the "server" for use in e.g. shell
    > scripts.
    > see e.g. http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html
     
    jose luis fernandez diaz, May 3, 2004
    #4
  5. On Mon, 03 May 2004 07:27:39 -0700, jose luis fernandez diaz wrote:

    > This solution forces to write a C client program. In this case a
    > prefer to use a CORBA communication framework. Anyway, is there

    Ugh. big and bloated corba. I'd rather take SunRPC over domain
    sockets for such purposes.
    Depending ofcourse on what you need to communicate back and
    forth to the server the C program wouldn't be very many lines.
    > another way to comunicate directly from the shell to a background
    > proccess without a client program ?

    You can create a named pipe, have the server read from that, and the
    client write to it (a shell script can easily write to a named pipe)
    Or listen on a ip socket, and implement some text protocol (e.g. http)
    and script it with netcat or similar.
    Thinking about it netcat or a similar tool can probably connect
    to a unix domain socket as well..

    --
    Nils Olav Selåsdal
    System Engineer
    w w w . u t e l s y s t e m s . c o m
     
    =?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=, May 3, 2004
    #5
  6. jose luis fernandez diaz

    Guest

    (jose luis fernandez diaz) writes:

    > This solution forces to write a C client program. In this case a
    > prefer to use a CORBA communication framework. Anyway, is there
    > another way to comunicate directly from the shell to a background
    > proccess without a client program ?


    CORBA? That's better than a short C program?

    If you're using ksh, you can use coprocesses, run the C program that
    way, and you can just write to its stdin. For example, in ksh:

    #! /bin/ksh
    echoprog |&
    print -p "this is a test"
    read -p echoline
    echo $echoline
    printf "%s\n" "$echoline"

    where "echoprog" is some program that just echos back what it reads
    from stdin. Adjust accordingly.

    Joe
    --
    "Surprise me"
    - Yogi Berra when asked where he wanted to be buried.
     
    , May 3, 2004
    #6
  7. jose luis fernandez diaz

    Xenos Guest

    "jose luis fernandez diaz" <> wrote in
    message news:...
    > This solution forces to write a C client program. In this case a
    > prefer to use a CORBA communication framework. Anyway, is there
    > another way to comunicate directly from the shell to a background
    > proccess without a client program ?
    >
    > Thanks,
    > Jose Luis.
    >

    CORBA is extreme overkill of such a small problem.
     
    Xenos, May 3, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Kial
    Replies:
    0
    Views:
    379
    Ben Kial
    Oct 12, 2003
  2. Phillip B Oldham

    Event-driven framework (other than Twisted)?

    Phillip B Oldham, Oct 1, 2008, in forum: Python
    Replies:
    15
    Views:
    683
    James Mills
    Oct 2, 2008
  3. snacktime

    event driven framework for ruby

    snacktime, Aug 9, 2005, in forum: Ruby
    Replies:
    29
    Views:
    482
    Joel VanderWerf
    Aug 12, 2005
  4. Tobias M.
    Replies:
    0
    Views:
    126
    Tobias M.
    Dec 23, 2013
  5. Chris Angelico
    Replies:
    0
    Views:
    86
    Chris Angelico
    Dec 23, 2013
Loading...

Share This Page