The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make the parent process to wait for the child process sennidurai Shell Programming and Scripting 7 09-30-2009 04:32 AM
catching a signal from child process emil2006 High Level Programming 2 05-03-2008 09:20 AM
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-10-2008 12:22 AM
catch SIGCHLD signal in parent process ranjan UNIX for Advanced & Expert Users 2 06-10-2005 01:52 AM
parent and child process question? tosa High Level Programming 0 02-16-2005 03:04 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
vkn_1985 vkn_1985 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 4
Thank you. Now I get it.

Hey, I have two more questions. I was trying sigaction before fork(), but I see some unexpected results!
1. I trigger SIGINT signal only once using kill function. I expect this to trigger respective signal handler and do the operation. But even if I am sending SIGINT only once, I am getting "Signal processed OKay" printed twice! Shouldn't this be printed only once as I am sending SIGINT only once?

Output :

Code:
Signal processed OKay 7006 0 Success SIGINT signal caught!!
Signal processed OKay 7006

Source code :

Code:
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
static void sig_usr(int signo){
if(signo == SIGINT){
char buf[] = "SIGINT signal caught!!\n";
int wr = strlen(buf);
write(STDOUT_FILENO, buf, wr);
}
return;
}

int main(void)
{
    pid_t pid, ppid;
    ppid = getpid();
    struct sigaction sig;
    sigemptyset(&sig.sa_mask);
    sig.sa_flags = 0;
    sig.sa_handler = sig_usr;
    if(sigaction(SIGINT,&sig,NULL) == 0)
                printf("Signal processed OKay ");
    sleep(10);
    printf("%d ", ppid);
    if((pid = fork()) == 0)
    { //Child    
        kill(ppid, SIGINT);
    }
}


2. Secondly, I am facing some problems when I try to send 2 SIGINT signals one after the other continuously from child process! i.e, when another kill() function is used after the first one in above code. The result I expected was two "SIGINT signal caught!!" messages. But I am getting only one instead.
In general, if I am sending signals of same kind continuously of same kind from child to parent, anything in particular I need to do?

Sorry for the elongated mail. Please help.

Regards!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0