Can I get the command at the same time while I running the process in 3

问题内容:

I study systemProgramming in C.
My question is “running 3-sample process and i can push command
this is my code

command.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define TOTALFORK 3

void main(){
    pid_t pids[TOTALFORK],pid;
    int runProcess = 0;
    int status;

    while(runProcess < TOTALFORK){
        pids[runProcess] = fork();
        if(pids[runProcess] < 0){
            perror("pipe error");
            exit(-1);
        }else if(pids[runProcess] == 0){
            execl("sample","sample",NULL);
        }else{
            printf("parent \n");
        }
        runProcess++;
    }
    wait(&status);
}

sample.c
#include <stdio.h>
#include <stdlib.h>
void main(){
    printf("Hi\n");
    sleep(20);
    printf("bye\n");
    exit(0);
}

so i want like that


$command


Hi


Hi


Hi


hello! // This is my writing


command:hello! // This is command.c


good!


command:good!


bye


bye


bye


So where I push input stream? in command.c

问题评论:

1  
perror("pipe error"); is very misleading since you’re not calling pipe – you’re calling fork
    
which part of your program prints good & hello ?
    
that is my questions
– Mono
7 mins ago

原文地址:

https://stackoverflow.com/questions/47756179/can-i-get-the-command-at-the-same-time-while-i-running-the-process-in-3

Tags:,

添加评论