Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- pid_t cree_process(void)
- {
- pid_t pid;
- /* On fork() tant que l'erreur est EAGAIN */
- do {
- pid = fork();
- } while ((pid == -1) && (errno == EAGAIN));
- return pid;
- }
- void fils_process(void)
- {
- if (execv("/usr/bin/gedit",NULL) == -1) {
- perror("execv");
- exit(EXIT_FAILURE);
- }
- }
- void pere_process(void)
- {
- printf("\n gedit est en cours de l'ouverture!\n");
- }
- int main(int argc, char *argv[])
- {
- pid_t pid = cree_process();
- switch (pid) {
- /* Si on a une erreur irrémédiable (ENOMEM dans notre cas) */
- case -1:
- perror("fork");
- return EXIT_FAILURE;
- break;
- /* Si on est dans le fils */
- case 0:
- fils_process();
- break;
- /* Si on est dans le père */
- default:
- pere_process();
- break;
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement