Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <time.h>
- #include <pthread.h>
- /* Beachten Sie den geaenderten Prototypen von main(). Referenz: man 2 execve */
- /* Sie koennen "envp" als Environment-Pointer an Kind-Prozesse weiterreichen. */
- int main(int argc, char *argv[], char *envp[])
- { struct timespec before;
- struct timespec after;
- pid_t funktionauslangerung =-1;
- funktionauslangerung = fork();
- if (funktionauslangerung < 0) {
- perror("FORK ERROR\n");
- exit(EXIT_FAILURE);
- }
- if (funktionauslangerung == 0) {
- execve(argv[1], &argv[1],envp);
- perror("ERROR");
- exit(EXIT_FAILURE);
- }
- else {
- pid_t child_status = -1;
- //Zeitmessen
- clock_gettime(CLOCK_MONOTONIC, &before);
- waitpid(funktionauslangerung, &child_status, 0);
- clock_gettime(CLOCK_MONOTONIC, &after);
- printf("Prozess %ld ends with status %ld after %ld us\n",
- (long int)funktionauslangerung,child_status,(after.tv_sec-before.tv_sec)*1000);
- ;}
- exit(0);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement