LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-24-2010, 01:09 PM   #1
Iyyaaz
LQ Newbie
 
Registered: Dec 2010
Posts: 4

Rep: Reputation: 0
Lightbulb Parent, Child processing with signaling............


Hi,
Here is a program that should print infinite messges as first child should print message and then the parent should print message. This loop should contnue but in the prgram it stops or terminates.

Can anybody point out the mistakes and correct the code please?

#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>

void foo();

int main(int argc, char *argv[])
{

if(fork())
foo() ;

while(1)
{
waitpid(1, (int *)1, WUNTRACED);//wait for child
printf("\nParent process = %d send signal\n", getpid());
kill(getppid()+1, SIGCONT);
}
}

void foo()
{
while(1)
{
printf("\nChild process = %d received signal\n", getpid());
kill(getpid(), SIGSTOP);

}

}
 
Old 12-26-2010, 07:58 PM   #2
linuxyeung
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Rep: Reputation: 0
Try this:

int main(int argc, char *argv[])
{
pid_t child_pid;
if((child_pid = fork()) == 0)
foo() ;

while(1)
{
waitpid(1, (int *)1, WUNTRACED);//wait for child
printf("\nParent process = %d send signal\n", getpid());
kill(child_pid, SIGCONT);
}
}
 
Old 12-26-2010, 07:59 PM   #3
linuxyeung
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Rep: Reputation: 0
getppid() return the parent pid. You need to send SIGCONT to the child process.
 
Old 01-16-2011, 05:57 AM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

It also is a near duplicate of: http://www.linuxquestions.org/questi....php?p=4202280
& the discussion could have been continued there.

As asked there, please make your next post an answer to this question:
Is this homework?
Thank you for your co-operation.
 
Old 01-16-2011, 09:58 PM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by archtoad6 View Post
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
OFFTOPIC
This is not the programming section, this thread is not directly related to kernels, should be moved to programming, also please put his code in code tags with indentations and I am sorry, I should have written all this in a report instead of writing it here

Last edited by Aquarius_Girl; 01-16-2011 at 10:08 PM.
 
  


Reply



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
Parent and child process Iyyaaz Programming 4 01-02-2011 11:20 AM
File descriptors shared between child and parent causing parent to hang. bharadiaam Linux - Newbie 1 03-02-2009 01:01 AM
return value from child to parent process prabhat ranjan Programming 3 02-12-2008 06:40 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:05 PM.

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
Open Source Consulting | Domain Registration