|
Mostrar Mensajes
|
Páginas: [1] 2 3
|
1
|
Programación / Programación C/C++ / Re: Manipulación de archivos
|
en: 23 Noviembre 2013, 17:59 pm
|
SOLUCIONADO. Por si alguien necesita el código, lo dejo como aporte. #include<unistd.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #include<errno.h> #include<sys/types.h> #include<dirent.h> #include<string.h> int main(int argc, char *argv[]) { DIR *dir; struct dirent *ent; char **ptr; long octal; printf("\nError al introducir el numero de digitos del parametro 2\n"); } if( (dir=opendir(argv[1]))==NULL){ printf("\nError en el primer open\n"); } octal = strtol(argv [2], ptr , 8); struct stat atributos; int fd; while ((ent = readdir(dir)) != NULL){ if( (strcmp(ent ->d_name , ".")!=0) && (strcmp(ent ->d_name , "..")!=0) ){ if ( (stat(ent->d_name, &atributos)) <0){ } if( (atributos.st_mode & S_IRUSR) != 0) else if( (atributos.st_mode & S_IWUSR) != 0) else if( (atributos.st_mode & S_IXUSR) != 0) else if( (atributos.st_mode & S_IRGRP) != 0) else if( (atributos.st_mode & S_IWGRP) != 0) else if( (atributos.st_mode & S_IXGRP) != 0) else if( (atributos.st_mode & S_IROTH) != 0) else if( (atributos.st_mode & S_IWOTH) != 0) else if( (atributos.st_mode & S_IXOTH) != 0) else if( (chmod(ent->d_name, octal)) <0){ } if ( (stat(ent->d_name, &atributos)) <0){ } if( (atributos.st_mode & S_IRUSR) != 0) else if( (atributos.st_mode & S_IWUSR) != 0) else if( (atributos.st_mode & S_IXUSR) != 0) else if( (atributos.st_mode & S_IRGRP) != 0) else if( (atributos.st_mode & S_IWGRP) != 0) else if( (atributos.st_mode & S_IXGRP) != 0) else if( (atributos.st_mode & S_IROTH) != 0) else if( (atributos.st_mode & S_IWOTH) != 0) else if( (atributos.st_mode & S_IXOTH) != 0) else } } }
|
|
|
2
|
Programación / Programación C/C++ / Re: Manipulación de archivos
|
en: 23 Noviembre 2013, 17:47 pm
|
El codigo completo seria este (aunque no funciona): #include<unistd.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #include<errno.h> #include<sys/types.h> #include<dirent.h> #include<string.h> int main(int argc, char *argv[]) { DIR *dir; struct dirent *ent; char **ptr; long octal; printf("\nError al introducir el numero de digitos del parametro 2\n"); } if( (dir=opendir(argv[1]))==NULL){ printf("\nError en el primer open\n"); } octal = strtol(argv [2], ptr , 8); struct stat atributos; int fd; while ((ent = readdir(dir)) != NULL){ if( (strcmp(ent ->d_name , ".")!=0) && (strcmp(ent ->d_name , "..")!=0) ){ if ( (fd = open(ent->d_name,O_RDONLY))<0){ printf("\nError en el segundo open\n"); } if ( (stat(ent->d_name, &atributos)) <0){ } if( (atributos.st_mode & S_IRUSR) != 0) else if( (atributos.st_mode & S_IWUSR) != 0) else if( (atributos.st_mode & S_IXUSR) != 0) else if( (atributos.st_mode & S_IRGRP) != 0) else if( (atributos.st_mode & S_IWGRP) != 0) else if( (atributos.st_mode & S_IXGRP) != 0) else if( (atributos.st_mode & S_IROTH) != 0) else if( (atributos.st_mode & S_IWOTH) != 0) else if( (atributos.st_mode & S_IXOTH) != 0) else if( (chmod(ent->d_name, octal)) <0){ } if( (atributos.st_mode & S_IRUSR) != 0) else if( (atributos.st_mode & S_IWUSR) != 0) else if( (atributos.st_mode & S_IXUSR) != 0) else if( (atributos.st_mode & S_IRGRP) != 0) else if( (atributos.st_mode & S_IWGRP) != 0) else if( (atributos.st_mode & S_IXGRP) != 0) else if( (atributos.st_mode & S_IROTH) != 0) else if( (atributos.st_mode & S_IWOTH) != 0) else if( (atributos.st_mode & S_IXOTH) != 0) else close(fd); } } }
|
|
|
3
|
Programación / Programación C/C++ / Manipulación de archivos
|
en: 23 Noviembre 2013, 17:01 pm
|
¿Por qué no me funciona el stat? #include<unistd.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> #include<errno.h> #include<sys/types.h> #include<dirent.h> #include<string.h> int main(int argc, char *argv[]) { DIR *dir; struct dirent *ent; char **ptr; long octal; printf("\nError al introducir el numero de digitos del parametro 2\n"); } if( (dir=opendir(argv[1]))==NULL){ printf("\nError en el primer open\n"); } octal = strtol(argv [2], ptr , 8); struct stat *atributos; int fd; while ((ent = readdir(dir)) != NULL){ if( (strcmp(ent ->d_name , ".")!=0) && (strcmp(ent ->d_name , "..")!=0) ){ if ( (fd = open(ent->d_name,O_CREAT|O_TRUNC|O_WRONLY,S_IRGRP|S_IWGRP|S_IXGRP))<0){ printf("\nError en el segundo open\n"); } if ( (stat(ent->d_name, atributos)) <0){ } chmod(ent->d_name, octal); close(fd); } }
|
|
|
4
|
Programación / Programación C/C++ / Ayuda con ejercicio de Hebras/Hilos y semaforos
|
en: 26 Octubre 2013, 21:14 pm
|
EEl programa compila, pero no funcion por lo que no se cual puede ser el error. #include <iostream> #include <pthread.h> #include <semaphore.h> using namespace std; const int num_items = 75 ; const int tam_vec = 15 ; int vector[tam_vec] ; int primera_libre = 0 ; int primera_ocupada = 0 ; sem_t puede_leer, puede_escribir ; int producir_dato(){ int contador = 1 ; return contador++ ; } void consumir_dato( int dato ){ cout << "dato recibido: " << dato << endl ; } void * productor( void * ){ for( unsigned i = 0 ; i < num_items ; i++ ){ if (primera_libre == tam_vec) primera_libre = 0; int dato = producir_dato() ; sem_wait (&puede_escribir); vector[primera_libre] = dato ; primera_libre++; sem_post(&puede_leer); } } void * consumidor( void * ){ for( unsigned i = 0 ; i < num_items ; i++ ){ int dato ; if (primera_ocupada == tam_vec) primera_ocupada = 0; sem_wait (&puede_leer); dato = vector[primera_ocupada] ; primera_ocupada++ ; sem_signal(&puede_escribir); consumir_dato( dato ) ; } } int main(){ pthread_t consumidora, productora; sem_init( &puede_leer, 0, 1); sem_init( &puede_escribir, 0 , 0); pthread_create(&productora, NULL, productor, NULL); pthread_create(&consumidora, NULL, consumidor, NULL); pthread_join( productora, NULL ) ; pthread_join( consumidora, NULL ) ; sem_destroy( &puede_escribir ); sem_destroy( &puede_leer ); }
|
|
|
6
|
Programación / Programación C/C++ / Necesito ayuda urgente con hebras/hilos y semaforos
|
en: 26 Octubre 2013, 14:54 pm
|
El problema basicamente es: #include <iostream> #include <pthread.h> using namespace std ; void* proc1( void* arg ) { for( unsigned long i = 0 ; i < 5000 ; i++ ) cout << "hebra 1, i == " << i << endl ; return NULL ; } void* proc2( void* arg ) { for( unsigned long i = 0 ; i < 5000 ; i++ ) cout << "hebra 2, i == " << i << endl ; return NULL ; } int main() { pthread_t hebra1, hebra2 ; pthread_create(&hebra1,NULL,proc1,NULL); pthread_create(&hebra2,NULL,proc2,NULL); pthread_exit(NULL); // permite continuar a hebra1 y hebra2 }
Y me da este error: /tmp/ccPPYPph.o: En la función `main': ej.cpp:(.text+0xd7): referencia a `pthread_create' sin definir ej.cpp:(.text+0xf2): referencia a `pthread_create' sin definir collect2: error: ld devolvió el estado de salida 1
Por lo que pienso que es que no me funciona el pthread.h. El ejercicio está bien porque es un ejemplo de los apuntes. Ayuda por favor, necesito una respuesta rápido. Nota: tampoco me funciona los semaforos asi que si hay que instalar un paquete o algo decidmelo por favor.
|
|
|
7
|
Sistemas Operativos / GNU/Linux / Error: Cannot retrieve repository metadata (repomd.xml) for repository: fedora.
|
en: 17 Octubre 2013, 18:39 pm
|
He estado buscando por internet y aparece un montón de gente con este error pero las soluciones que ponen no me funcionan. Por favor ayudenme. fedora.repo: [fedora] name=Fedora $releasever - $basearch failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch enabled=1 metadata_expire=7d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [fedora-debuginfo] name=Fedora $releasever - $basearch - Debug failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-debug-$releasever&arch=$basearch enabled=0 metadata_expire=7d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [fedora-source] name=Fedora $releasever - Source failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-source-$releasever&arch=$basearch enabled=0 metadata_expire=7d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
fedora-updates.repo: [updates] name=Fedora $releasever - $basearch - Updates failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [updates-debuginfo] name=Fedora $releasever - $basearch - Updates - Debug failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/debug/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch [updates-source] name=Fedora $releasever - Updates Source failovermethod=priority baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/SRPMS/ #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearch enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
|
|
|
8
|
Sistemas Operativos / GNU/Linux / Re: Ayuda con partición Ubuntu
|
en: 13 Octubre 2013, 18:35 pm
|
Bah, gracias por la "ayuda" xD. Pero por fin, después de 7 horas, conseguí arreglarlo solo. Tutoriales de youtube rulez. Y por si alguien le interesa, era lo que estaba dudando, una partición mal hecha.
|
|
|
|
|
|
|