Inter program communication!!

This is a discussion on Inter program communication!! within the C Programming forums, part of the General Programming Boards category; Hi to all, My problem is as follows: Program1 and Program2 are two separate C programs - Program1 is in ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    22

    Inter program communication!!

    Hi to all,

    My problem is as follows:

    Program1 and Program2 are two separate C programs - Program1 is in Linux kernel whereas Program2 is a user space program that I've written. How can I send a signal from Program1 to Program2?

    Each time Program1 is executed, a kind of signal is sent to Program2 to tell it to start its execution. But the execution of both programs needs to continue in paralell. Program1 mustn't wait for Program2 to finish its execution in order to continue. After Program2 finishes executing, it then waits for the next call (signal) from Program1 telling it to execute again.

    I can't use fork() or threads because the overhead is far too much than what I can support. What is the best way that I can implement this? Signals?

    Any input and examples will be very much appreciated..

    Warm regards,
    Visham

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Sounds to me like program1 is a driver, in which case making it conform to the standard driver model of supporting open, close, read, write and ioctl would seem to be a good idea.

    It works for everything else.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    fork() creates process, you already have 2 processes, how is that too much overhead for what you already have?
    Threads run in the same virtual address space, which is even less than 2 processes...how is that too much overhead?

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi,

    Many thx for the replies...

    Program1 is actually part of iptables kernel code. I have written a userspace program that needs to be executed on a packet basis. I can't afford to create processes or threads for each packet that goes through Program1, and then have to kill them afterwards. I kind of need something that executes and then waits for the next time it is told to execute. When a packet enters the Program1 code, Program1 has to issue a signal of some kind to Program2 to start its execution. But Program1 must continue its execution in parallel as Program2 executes. Program2 finishes its execution and then waits for the next signal from Program1.

    I'm having real difficulties doing it. Maybe some one among you can help me out of this..

    Warm regards,
    Visham

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    So what does program1 do if program2 isn't running or stuck in a loop ignoring the outside world?

    > I'm having real difficulties doing it.
    Perhaps you should look at how the ethereal scanner works (www.ethereal.com)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi,

    Program1 is part of the iptables kernel code...it checks packet attributes against iptables rules. Before Program1 declares a packet as valid and accepts it, it has to send a signal to userspace Program2, which will then start executing. After Program1 sends the signal , it does not wait for Program2 to finish. Both programs continue execution in paralell. Program1 is called every time a packet is sent or received. So Program two will execute every time Program1 is called.

    Can you help..I having real problems with the signalling part. Can u give me basic signal examples that can be applied to the above. It's pretty tough for me to work with signals..

    Regards,
    Visham

  7. #7
    Registered User
    Join Date
    Jun 2005
    Location
    Stockholm, Sweden
    Posts
    64
    You could try reading the book Advanced Linux Programming, specifically the parts about inter-process communication.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi to all,

    Can anyone give me a simple example of how sigaction() is used, i.e how is the signal generated, sent and caught? This might help me with the program i described above.

    Warm regards,
    Visham

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I have no idea, but try this.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Signalling is a very crude (and expensive) interface, one which isn't suitable for a high bandwidth interface. Your best bet is to look around say sourceforge for other programs which do what you want (and examine that source code), or ask other people who know more about the details of IP tables.

    You're not trying to implement an Intrusion Detection System (IDS) like Snort by any chance are you?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi to all,

    I am not trying to implement an IDS..what i'm trying to implement resembles a program calling another program, like detailed in one of the FAQs. However, instead of creating an entire process each time (using fork() and execv()), i just want to signal the other program to start its execution. The signal is just sent from Program1 to Program2. Then both programs continue their executions independently and in parallel, as in the FAQ example (using fork() and execv()).

    I chose signalling because the overhead compared to the creation of a thread or process is must less.

    I'm currently trying to do the signal part using sigaction().

    I need some very simple example of how sigaction works..the ones i've come across are complicated.

    If anyone of you come across any good simple example, feel free to post it for me.

    Many thx & warm regards,
    Visham

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Why would you create a thread for each packet? What are you actually trying to do? It sounds like you don't even understand that. You should probably read How To Design Programs, you'r design sounds incredibly flaws/unresearched. Please provide us with useful information. You don't want signals, they are terrible in *NIX. Why does the packet program need to be part of the kernel? Why does this need to be 2 programs? Why do you think you need to make a new thread for every packet? Why can't you get the packet and process in the same process?

  13. #13
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi,

    tell me sth..why do you consider signals so terrible? I think signals are best when it comes to asynchronous event notification. I'm not trying to create a thread for each packet. Actually, that's what i'm trying to avoid using signals. Program1 is part of the iptables code. This is by default in the kernel. I'm only trying to modify it. It simply has to generate and raise a signal when a packet meets certain criteria and is accepted. That's all it does.

    Program2 is a user space program that does some logging and does dynamic iptables firewall script updating. Ths takes place when Program2 receives the signal from Program1.This updating cannot be performed from inside the kernel.

    That's the best explanation i can give of what i'm trying to do..

    Warm regards,
    Visham

  14. #14
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    In other words, an IDS with adaptive rules.

    See previous replies.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  15. #15
    Registered User
    Join Date
    Sep 2005
    Posts
    22
    Hi,

    No it's not an IDS...i'm doing load balancing on firewalls..I'll be working on Snort in some 4 months time.

    Regards,
    Visham

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. C program for Inter Process communication ( Tx and RX)
    By hiharsh in forum C Programming
    Replies: 3
    Last Post: 05-03-2007, 10:23 AM
  3. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21