Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- int main(int argc, char *argv[]) //argc = argument count, argv = argument vector
- {
- int i;
- for(i = 1; i < argc; i++)
- {
- printf("%dth argument: %s\n", i , argv[i]);
- pid_t child = fork();
- if(child == 0)
- {
- int commandExitStatus = execlp(argv[i], argv[i], NULL);
- if ( commandExitStatus == -1)//Failed
- printf("%d",commandExitStatus);
- else
- printf("Successful");
- exit(0);
- }
- }
- printf("============= END ===============\n");
- /* This code runs concurrently
- int i = 10;
- while (i > 0)
- {
- pid_t child = fork();
- if(child == 0) {
- printf("i: %d\n", i--);
- exit(0);
- }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement