Ajout du script 'apres.c' qui permet de lancer une commande en différé, résultat dans nohup.out

master
Philippe Pittoli 2011-02-07 21:50:49 +01:00
parent 61476b59b7
commit d96c42c3c9
3 changed files with 102 additions and 0 deletions

46
apres.c Normal file
View File

@ -0,0 +1,46 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/signal.h>
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);
}

17
mini_shell.c Normal file
View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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," ");
}

39
supprime.c Normal file
View File

@ -0,0 +1,39 @@
// THIS DOESN'T WORK
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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;
}
}