C program that makes use of the system calls for creating processes
I want to make a C program that makes use of the system calls for creating processes. The program should receive from the command line an undetermined number of Linux commands to execute them in parallel or in sequence according to the option entered by the user.
executeCommand [-p|-s] comand1 comand2
where p - parallel (for each command, the parent process mu开发者_运维问答st create a child process that executes the corresponding command.)
and s - sequence (the parent process should create child process to each command performed, but the process that run the second command will have to wait for the process running the command to complete the first and third command will have to wait for the end of implementation of the second, etc.)
so basically i want that user do something like
./executeCommand -p ls\ -lisa cat\ fork.c
#include<stdio.h>
int main(int argc, char *argv[]){
execl("/bin/ls","ls",NULL);
}
Some hints would be appreciated!
Like told above, fork, wait and the exec family should be enought for you to implement the mini-shell.
For advanced command line arguments parsing, you can take a look to getopt
Here's a link on a tutorial: Parsing Program Arguments
You need fork
. You need the different kinds of exec
and wait
calls.
Those system calls should be all that you need.
精彩评论