Find the answer to your Linux question:
Results 1 to 4 of 4
Hi. I'm having quite a headache trying to communicate two processes which have no relation (one is not the child of the other). I use SIGUSR1 for this purpose. i ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    3

    Using signals between unrelated processes (C)

    Hi. I'm having quite a headache trying to communicate two processes which have no relation (one is not the child of the other). I use SIGUSR1 for this purpose. i just want to send one signal from process 1 to process 2 so that this last process prints something in the console. Instead, it prints "User defined signal 1" and exits. I know this is the default behaviour but i'm installing a signal handler which supposedly just prints something. Any help'll be appreciated. Thanks

  2. #2
    Linux Newbie SagaciousKJB's Avatar
    Join Date
    Aug 2007
    Location
    Yakima, WA
    Posts
    162
    Well, it would be helpful to see your source. It should look something like so

    Code:
    #include <signal.h>
    
    ...
    
    static void handler(int sig, siginfo_t *si, void *unused)
    {
               printf("%.2lf cps\n", (float)count/(time(0) - start));
    }
    
    ...
    
    struct sigaction sa;
    
            sa.sa_flags = SA_SIGINFO;
            sigemptyset(&sa.sa_mask);
            sa.sa_sigaction = handler;
    
    if (sigaction(SIGUSR1, &sa, NULL) == -1)
                            ;
    The "struct sigaction" is defined in signal.h, so sa.sa_flags is defined as such in there. sa.sa_sigaction is just a pointer to a function which is the signal handler.

    As far as sending a SIGUSR1 to another process, I'm not sure how one would do this in C, I have just done it with the "kill" application".

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Do note that to set a signal on another process, you either have to be the owner of that process, or root. This keeps one user from killing processes of another user.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Linux Newbie tetsujin's Avatar
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by SagaciousKJB View Post
    As far as sending a SIGUSR1 to another process, I'm not sure how one would do this in C, I have just done it with the "kill" application".
    The "kill" system call, of course.

Posting Permissions

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