LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 07-20-2003, 06:06 AM   #1
winwar
LQ Newbie
 
Registered: Jul 2003
Posts: 3

Rep: Reputation: 0
about parent and child process


If parent process created a child process by "fork()", how can parent end the child process? Thanks!
 
Old 07-22-2003, 05:10 AM   #2
dharmender_rai
Member
 
Registered: Aug 2002
Location: Pune,India
Posts: 39

Rep: Reputation: 15
Hi,
After forking, there are two different processes sharing some thing like text (code) section etc. Child knows the process id of its parent ( that information can be got from getppid() ) but it is not possible for the parent to know the id's of its children.
There is a work around for this. You can use shared memory ( list implementation) that would be used by the children to put there and parent's id while the parent would go through that list and if its id is there on the node as the parent id, it would kill the child process using kill() as child has put its pid information there.

Hope that it would help you to some extent.

Dharmender Rai
 
Old 07-23-2003, 01:22 AM   #3
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
ithink there is no problem in knowing the pid of a child process ...
so kill() would work just fine...


fork returns twice..once in the child (where it returns 0)
and once in the parent where it is a positive value that is the pid of the child process..you can alway do a kill on it

>>>code
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
int main(void)
{
int pid;
pid = fork();

if ( pid == 0)
{
printf("in child with pid = %d\n",getpid());
sleep(30);
_exit(0);
}
else
{
printf("n parent where child pid is = %d\n",pid);
kill(pid,SIGINT);
}
return 0;
}
 
Old 07-23-2003, 06:07 AM   #4
dharmender_rai
Member
 
Registered: Aug 2002
Location: Pune,India
Posts: 39

Rep: Reputation: 15
thanks. i just couldn't think in that way.
 
  


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
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 04:38 PM
Getting a parent to communicate with its child -- fork() kamel Programming 3 06-02-2004 03:04 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM
child and parent process error jdevanand Programming 1 04-29-2002 08:13 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 01:48 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