LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-02-2010, 02:18 PM   #1
chaoxifer
LQ Newbie
 
Registered: Nov 2010
Location: Seoul, South Korea
Distribution: Arch, Gentoo
Posts: 15

Rep: Reputation: 0
Why child process can't print strings after call signal_handler?


Hi all!

First, I'm sorry about my English writing skills.

I'm studying about signal in Linux Kernel and I got a problem about signal handler and output buffer.

I just want to know about stdout buffer related parent process and child process.

The problem is - parent process received SIGINT signal_handler that I implement is called.
And after signal_handler is called, it print string "pid : xxx state : RUNNING" ... but after end of signal_handler function, child process might be print string but it isn't print at all.

I'm not asking right code, but I want to know why is this happened and concepts about signal handler, buffer - between parent process and child process.

here is a code signal_handler:

Quote:
void TC3_handler()
{
pid_t pid;
ProcState ps;

pid = GetProcessId();
ps = GetProcessState( pid );

switch(ps) {
case PROC_STATE_RUNNING :
printf("pid : %d, state : RUNNING\n", pid);
break;
case PROC_STATE_READY :
printf("pid : %d, state : READY\n", pid);
break;
case PROC_STATE_BLOCKED :
printf("pid : %d, state : BLOCKED\n", pid);
break;
default :
printf("Out of range\n");
break;
}
}
this is the signal handler for SIGINT.

chlid process counts number in infinite loop, but after call signal_handler, it can't print at all.. just waiting for SIGINT..

What is the problem and What is the concepts that I missing...?

Thank you for reading.

Last edited by chaoxifer; 11-02-2010 at 02:27 PM.
 
Old 11-02-2010, 07:13 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
printing from inside the handler is a bad idea and could be the cause of the problem. Move those prints out and just set a variable in the handler so the program knows the sigint occurred.
 
Old 11-02-2010, 11:26 PM   #3
chaoxifer
LQ Newbie
 
Registered: Nov 2010
Location: Seoul, South Korea
Distribution: Arch, Gentoo
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by estabroo View Post
printing from inside the handler is a bad idea and could be the cause of the problem. Move those prints out and just set a variable in the handler so the program knows the sigint occurred.
Thanks for reply.

I solve the problem... It was too simple problem.

If I press Ctrl-C, and SIGINT is occured, both parent process and child process are received. I didn't block the signal on child process. So after child process received SIGINT, it didn't print number anymore.

It was too simple thing... that i was missing.

Anyway, Thank you for reply.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Child THREAD and Child PROCESS whho Linux - Newbie 12 02-16-2015 01:22 AM
Sending Signal from Child Process to Parent Process : Not getting desired output thelink123 Linux - General 4 10-26-2012 10:05 PM
Under which circumstances a child process creates another child process using fork? mitsulas Programming 3 12-08-2009 09:16 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 01:40 AM
Killing a child process from another child marri Programming 6 10-01-2004 08:08 PM


All times are GMT -5. The time now is 05:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration