The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-10-2008 12:22 AM
about child process compbug UNIX for Dummies Questions & Answers 12 03-22-2006 07:55 PM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 07:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 05:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 08:54 AM

Closed Thread
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 11-03-2003
Confuse Confuse is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 7
creating child process

i want to create 3 child processes from the same parent using folk. I know how to use folk but my child processes did not come from the same parent. Any suggestion what i did wrong ?
  #2 (permalink)  
Old 11-03-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
You must be getting the parent and child mixed up.
  #3 (permalink)  
Old 11-03-2003
Confuse Confuse is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 7
can u give me a sample code how u create 2 child process from the same parents ?
  #4 (permalink)  
Old 11-03-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Use our search function. There are several examples already in the forum.
  #5 (permalink)  
Old 05-24-2005
sanbiswa sanbiswa is offline
Registered User
  
 

Join Date: May 2005
Posts: 1
Let's say there is a process P; is there a way for it to know which process (the PID) has sent it a signal?
  #6 (permalink)  
Old 05-26-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
Arrow

hai im programming a simple program like you wanted, but its not working properly !!!

well first of all i want it to print A then B then A then B , five times
but i dont know y "for" is not working ?
with or without "for" it prints only "AB"

if this program works ill include it in my own script for my FC3 box!!
can you point whats wrong with my code?

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

int main(){
	pid_t one, two;
	char A = 'A';
	char B = 'B';
	int i=0;

	int desc = open ("aba.txt", O_CREAT | O_RDWR , 0700 );
	if ( desc < 0 ) {
		perror ( "open");
		exit(-1);
	}
	
	lseek(desc,0,sizeof(char));
	
for (i=0;i<5;i++){
	printf("%d\n",i);
	one = fork();
	if ( one == 0 ) {
		write(desc,&A,sizeof(char));
		exit(0);
	}
	else {
		
		two = fork();
		if ( two == 0 ) {
			write(desc,&B,sizeof(char));
		}
		exit(0);
	}
	
	waitpid(one,NULL,0);
	waitpid(two,NULL,0);
}
	close(desc);
	system("cat aba.txt");
}

  #7 (permalink)  
Old 05-26-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
am I lame ??
sounds like i didnt grab something !!!
ive changed my code now!!
whats wrong??
y for 2 loops, it prints 3 loops?

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

int main(){
	pid_t one, two;
	char A = 'A';
	char B = 'B';
	int i=0;

	int desc = open ("aba.txt", O_CREAT | O_RDWR , 0700 );
	if ( desc < 0 ) {
		perror ("open");
		exit(-1);
	}
	
	lseek(desc,0,sizeof(char));
	
	one = fork();

	switch ( one ) {
		case  0 : for(i=0;i<2;i++){
				write(desc,&A,sizeof(char));	
				two = fork();
				if ( two == 0 ) {
					write(desc,&B,sizeof(char));
				}
				waitpid(one,NULL,0);
				waitpid(two,NULL,0);
			  }
			  exit(0);
			  
		case -1 : perror("fork");
			  exit(-1);
			  
		default : close(desc);
			  system("cat aba.txt");
			  exit(0);
	}

}

Attached Thumbnails
creating-child-process-snapshot7.png  
Closed Thread

Bookmarks

Tags
linux

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 03:52 PM.


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