Click here to Skip to main content
15,914,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²25-Jul-03 21:24
Johnny ²25-Jul-03 21:24 
GeneralRe: Question about stdin under multi-process environment. Pin
George225-Jul-03 21:36
George225-Jul-03 21:36 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns25-Jul-03 23:15
Ryan Binns25-Jul-03 23:15 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 0:58
George226-Jul-03 0:58 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 1:01
Ryan Binns26-Jul-03 1:01 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 1:05
George226-Jul-03 1:05 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 2:10
Ryan Binns26-Jul-03 2:10 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 2:16
George226-Jul-03 2:16 
Thanks, Ryan buddy!

I have made an example to show the stdin are shared between parent and child process. And even if a process is waiting for input, it can still become inactive.

Sample code:
--------
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

main()
{
pid_t pid;
int rv;

switch(pid=fork()) {
case -1:
perror("fork"); /* something went wrong */
exit(1); /* parent exits */

case 0:
while (1)
{
printf("In child process \n");
scanf(" %d", &rv);
printf("Child read: %d \n", rv);
}
exit(rv);

default:
while (1)
{
printf("In parent process \n");
scanf(" %d", &rv);
printf("Parent read: %d \n", rv);
}
wait(&rv);
printf("PARENT: My child's exit status is: %d\n", WEXITSTATUS(rv));
printf("PARENT: I'm outta here!\n");
}
}

--------

Output from my Linux box,
--------
[root@localhost ml]# ./MultiProcessStdin
In parent process
In child process
10
Child read: 10
In child process
20
Parent read: 20
In parent process
30
Child read: 30
In child process
40
Parent read: 40
In parent process
--------

So, you are wrong. Smile | :)


George
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 2:38
Ryan Binns26-Jul-03 2:38 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 2:44
George226-Jul-03 2:44 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²26-Jul-03 4:28
Johnny ²26-Jul-03 4:28 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 16:48
George226-Jul-03 16:48 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²26-Jul-03 21:30
Johnny ²26-Jul-03 21:30 
GeneralRe: Question about stdin under multi-process environment. Pin
George227-Jul-03 1:14
George227-Jul-03 1:14 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²27-Jul-03 6:52
Johnny ²27-Jul-03 6:52 
GeneralRe: Question about stdin under multi-process environment. Pin
George227-Jul-03 15:40
George227-Jul-03 15:40 
GeneralRe: Question about stdin under multi-process environment. Pin
Bob Stanneveld25-Jul-03 23:55
Bob Stanneveld25-Jul-03 23:55 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 1:03
George226-Jul-03 1:03 
GeneralRe: Question about stdin under multi-process environment. Pin
Bob Stanneveld27-Jul-03 1:09
Bob Stanneveld27-Jul-03 1:09 
GeneralRe: Question about stdin under multi-process environment. Pin
George227-Jul-03 1:15
George227-Jul-03 1:15 
GeneralLinking error Pin
eddymohd25-Jul-03 17:58
eddymohd25-Jul-03 17:58 
GeneralRe: Linking error Pin
Michael Dunn25-Jul-03 18:20
sitebuilderMichael Dunn25-Jul-03 18:20 
GeneralRe: Linking error Pin
eddymohd25-Jul-03 19:08
eddymohd25-Jul-03 19:08 
GeneralRe: Linking error Pin
Bob Stanneveld25-Jul-03 19:32
Bob Stanneveld25-Jul-03 19:32 
GeneralRe: Linking error Pin
Michael Dunn25-Jul-03 20:21
sitebuilderMichael Dunn25-Jul-03 20:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.