From d96c42c3c93c4438fb0f2f908e5c10913eb1e503 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 7 Feb 2011 21:50:49 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20du=20script=20'apres.c'=20qui=20permet?= =?UTF-8?q?=20de=20lancer=20une=20commande=20en=20diff=C3=A9r=C3=A9,=20r?= =?UTF-8?q?=C3=A9sultat=20dans=20nohup.out?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apres.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ mini_shell.c | 17 +++++++++++++++++ supprime.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 apres.c create mode 100644 mini_shell.c create mode 100644 supprime.c diff --git a/apres.c b/apres.c new file mode 100644 index 0000000..c2b93d7 --- /dev/null +++ b/apres.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include + +void erreur(char *s); +void suite(int n){}; + +int main(int argc, char ** argv) +{ + int temp, fd0, fd1, fd2, pid; + if((fd0 = open("/dev/null", O_RDONLY)) == -1) erreur("Ouverture fichier null"); + if((fd1 = open("nohup.out", O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1 ) erreur("Ouverture fichier nohup.out"); + if((fd2 = open("nohup.err", O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1 ) erreur("Ouverture fichier nohup.err"); + + pid = fork(); + + if(pid == 0) + { + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); + signal(SIGQUIT, SIG_IGN); + + close(0); dup(fd0); + close(1); dup(fd1); + close(2); dup(fd2); + + temp = atoi(argv[1]); + + signal(SIGALRM, suite); + alarm(temp); + pause(); + execvp(argv[2], argv + 2); + erreur("Le programme n'a pas fonctionné correctement"); + exit(-1); + } + printf("PID fils : %d\n", pid); +} +void erreur(char *s) +{ + perror(s); + exit(-2); +} diff --git a/mini_shell.c b/mini_shell.c new file mode 100644 index 0000000..d524330 --- /dev/null +++ b/mini_shell.c @@ -0,0 +1,17 @@ +#include +#include +#include + +int main(int argc, char **argv) +{ +} +void lire(char** arg1, char** arg2, char** arg3) +{ + char *s; + + s = lireChaine3(); + + *arg1 = strtok(s," "); + *arg2 = strtok((char *)0," "); + *arg3 = strtok((char *)0," "); +} diff --git a/supprime.c b/supprime.c new file mode 100644 index 0000000..b10f60c --- /dev/null +++ b/supprime.c @@ -0,0 +1,39 @@ +// THIS DOESN'T WORK +#include +#include +#include + +void supprime(char *s, char c); +int main(int argc, char **argv) +{ + char * chaine = "Salut tout le monde"; + char c = 'u'; + supprime(chaine, c); + printf("%s\t\t%c\n", chaine, c); + exit(0); +} + +void supprime(char *s, char c) +{ + char * save = s; + while(*s) + { + if(*s == c) + { + printf("On a une correspondance\n"); + while(*s && *(s + 1) != '\0') + { + *s = *(s + 1); + s++; + } + printf("Fin de la boucle : %s", s); + *s = '\0'; + s = save; + } + else + { + s++; + } + save = s; + } +}