Danny Sateler P1 #! /bin/bash #cd $1 /* Línea comentada */ ls for i in

Anuncio
Danny Sateler
P1
#! /bin/bash
#cd $1 /* Línea comentada */
ls
for i in $1 /* esto equivale a decir for i in directorio como directorio es sólo uno, i tomará sólo ese valor*/
do
if( $i = .o); then /* No recorre los subdirectorios */
rm -f $1$i /* falla cuando nombres tienen espacios, usar “$1$i” */
fi
if( $1 = *.class); then
rm -f $1$i
fi
done
15/25
P2
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
void main (void){
int pid;
if(!(pid=fork())){
//execlp("/bin/bash", "bash", NULL);
while(1);
//exit(0);
}
printf("Padre!!!\n");
waitpid(pid, NULL, 0);
sleep(2);
printf("Llego Control-C.\n");
exit(0);
}
/* En hijo hace espera infinita, usted no atiende llegada de control-C por lo tanto su programa termina tan pronto llega ésta
*/
12/25
P3
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
void main (void){
char s[100]; //Recibe la ecuación
int res; //Recibe el resultado
int i;
int pid_bc;
char c;
FILE *temp = fopen("temp", "w+");
FILE *temp2 = NULL;
do{
printf("Ingrese una ecuación:\n");
scanf("%s", s);
//puts(s);
if (!strcmp(s,"quit"))
exit (0);
else
i = 1;
//printf("I %i\n", i);
fprintf(temp,"%s\nquit", s);
scanf("%c",&c);
if (!(pid_bc=fork())){
printf("voy a escribir\n");
system("bc < temp > temp2");
sleep(1);
//system("echo $res");
//system("cat temp2");
printf("deje el bash\n");
exit(0);
}
/* Está de más */
waitpid(pid_bc, NULL, 0);
if (temp2==NULL)
temp2 = fopen("temp2", "r");
fscanf(temp2,"%i", &res);
printf("La respuesta es: %i\n", res);
fseek(temp, 0, 0);
fseek(temp2, 0, 0);
}while(i);
exit (0);
}
/* No vale mucho la pena tomar este curso si usted no intenta usar las herramientas enseñadas en el ramo.
Su solución no funciona aún cuando podría hacerlo, claro que en forma bastante menos eficiente que la solución de sus
compañeros. */
15/25
P4
No entrega
0/25
Descargar