CaptRage61
Programmer
I am using the fork command to run 2 progmrams at the same time, the ls command. I then pass in at the command line 2 args so that the first arg goes to the first ls and the second arg goes to the second ls. That works fine, the problem is I am getting too many program running, all I want to be displayed is the output of one then the output of the other.
For example if I run the command: ./prog -l --color=tty
here is my code anyone know how I can fix it??
For example if I run the command: ./prog -l --color=tty
here is my code anyone know how I can fix it??
Code:
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(int argc, char* argv[]){
int a = fork();
int b = fork();
int first,second;
if (a !=0){
//parent code
}
else{
//child code
first = execl("/bin/ls","ls",argv[1],NULL);
}
if (b !=0){
//parent code
}
else{
//child code
second = execl("/bin/ls","ls",argv[2],NULL);
}
}