Advertisement

11.24.2008 at 06:17AM PST, ID: 23930637 | Points: 500
[x]
Attachment Details

Signal handling in Linux with C

Asked by paddy8788 in Signal Processing, Linux Programming, C Programming Language

Tags: , ,

Hi!
I am doing my project to develop a simple shell. I have a problem with handling signals that I hope you guys can help me.

I am using signal() function to catch the signal sending from the forked children to the shell, which is:
            signal(SIGCHLD, handler);
However, this is really confusing. When the user input a command into my shell, normally the shell parse it and call the corresponding programs. However, when I have a pipe like:
ls | cat | cat | cat | cat > a.txt
Then there are multiple files running at once, and the signal handler does not seem to be able to catch multiple signal at one time...

I tried to use signal mask in my handler (in the code snippet).      

But this does not seem help... I also applied the race running idea with signal suspend function to delay the moment the child return the signal but also, it does not work because I think at some moment, two child sends two SIGCHLDs at once, and that is really hard to control...
Right now, what I am doing is ask for the children to wait 1 second before sending any signals to the parent, and this works actually. But I don't think this is a smart way to handle signal...

I hope you can help me. Thank you!

Thank you!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
sigset_t nmask, omask;	
	sigemptyset(&nmask);
	sigaddset(&nmask, SIGCHLD);
	signal(SIGCHLD, handler);
	sigprocmask(SIG_BLOCK, &nmask, &omask);			//Block all SIGCHLD signals
	/* My main code goes here */
	sigprocmask(SIG_SETMASK, &omask, NULL);			//Unblock SIGCHLD
 
Loading Advertisement...
 
[+][-]11.24.2008 at 07:13PM PST, ID: 23032208

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.25.2008 at 12:58AM PST, ID: 23033138

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081119-EE-VQP-49 - Hierarchy / EE_QW_2_20070628