elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  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.

Código
  1. #include<unistd.h>
  2. #include<sys/stat.h>
  3. #include<fcntl.h>
  4. #include<stdio.h>
  5. #include<errno.h>
  6. #include<sys/types.h>
  7. #include<dirent.h>
  8. #include<string.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. DIR *dir;
  13. struct dirent *ent;
  14. char **ptr;
  15. long octal;
  16.  
  17. if( strlen(argv[2]) != 4){
  18. printf("\nError al introducir el numero de digitos del parametro 2\n");
  19. exit(-1);
  20. }
  21.  
  22. if( (dir=opendir(argv[1]))==NULL){
  23. printf("\nError en el primer open\n");
  24. exit(-1);
  25. }
  26.  
  27. octal = strtol(argv[2], ptr, 8);
  28.  
  29. struct stat atributos;
  30. int fd;
  31. while ((ent = readdir(dir)) != NULL){
  32. if( (strcmp(ent->d_name, ".")!=0) && (strcmp(ent->d_name, "..")!=0) ){
  33.  
  34. printf("%s", ent->d_name);
  35. printf("%s", " : ");
  36.  
  37. if ( (stat(ent->d_name, &atributos)) <0){
  38. printf("\nError en stat\n");
  39. exit(-1);
  40. }
  41.  
  42. if( (atributos.st_mode & S_IRUSR) != 0)
  43. printf("%s", "r");
  44. else
  45. printf("%s", "-");
  46.  
  47. if( (atributos.st_mode & S_IWUSR) != 0)
  48. printf("%s", "w");
  49. else
  50. printf("%s", "-");
  51.  
  52. if( (atributos.st_mode & S_IXUSR) != 0)
  53. printf("%s", "x");
  54. else
  55. printf("%s", "-");
  56.  
  57. if( (atributos.st_mode & S_IRGRP) != 0)
  58. printf("%s", "r");
  59. else
  60. printf("%s", "-");
  61.  
  62. if( (atributos.st_mode & S_IWGRP) != 0)
  63. printf("%s", "w");
  64. else
  65. printf("%s", "-");
  66.  
  67. if( (atributos.st_mode & S_IXGRP) != 0)
  68. printf("%s", "x");
  69. else
  70. printf("%s", "-");
  71.  
  72. if( (atributos.st_mode & S_IROTH) != 0)
  73. printf("%s", "r");
  74. else
  75. printf("%s", "-");
  76.  
  77. if( (atributos.st_mode & S_IWOTH) != 0)
  78. printf("%s", "w");
  79. else
  80. printf("%s", "-");
  81.  
  82. if( (atributos.st_mode & S_IXOTH) != 0)
  83. printf("%s", "x");
  84. else
  85. printf("%s", "-");
  86.  
  87.  
  88.  
  89.  
  90. printf("%s", " ");
  91.  
  92. if( (chmod(ent->d_name, octal)) <0){
  93. printf("\nError en chmod\n");
  94. exit(-1);
  95. }
  96.  
  97. if ( (stat(ent->d_name, &atributos)) <0){
  98. printf("\nError en stat\n");
  99. exit(-1);
  100. }
  101.  
  102.  
  103.  
  104. if( (atributos.st_mode & S_IRUSR) != 0)
  105. printf("%s", "r");
  106. else
  107. printf("%s", "-");
  108.  
  109. if( (atributos.st_mode & S_IWUSR) != 0)
  110. printf("%s", "w");
  111. else
  112. printf("%s", "-");
  113.  
  114. if( (atributos.st_mode & S_IXUSR) != 0)
  115. printf("%s", "x");
  116. else
  117. printf("%s", "-");
  118.  
  119. if( (atributos.st_mode & S_IRGRP) != 0)
  120. printf("%s", "r");
  121. else
  122. printf("%s", "-");
  123.  
  124. if( (atributos.st_mode & S_IWGRP) != 0)
  125. printf("%s", "w");
  126. else
  127. printf("%s", "-");
  128.  
  129. if( (atributos.st_mode & S_IXGRP) != 0)
  130. printf("%s", "x");
  131. else
  132. printf("%s", "-");
  133.  
  134. if( (atributos.st_mode & S_IROTH) != 0)
  135. printf("%s", "r");
  136. else
  137. printf("%s", "-");
  138.  
  139. if( (atributos.st_mode & S_IWOTH) != 0)
  140. printf("%s", "w");
  141. else
  142. printf("%s", "-");
  143.  
  144. if( (atributos.st_mode & S_IXOTH) != 0)
  145. printf("%s\n", "x");
  146. else
  147. printf("%s\n", "-");
  148.  
  149.  
  150. }
  151. }
  152.  
  153.  
  154. }
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):

Código
  1. #include<unistd.h>
  2. #include<sys/stat.h>
  3. #include<fcntl.h>
  4. #include<stdio.h>
  5. #include<errno.h>
  6. #include<sys/types.h>
  7. #include<dirent.h>
  8. #include<string.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. DIR *dir;
  13. struct dirent *ent;
  14. char **ptr;
  15. long octal;
  16.  
  17. if( strlen(argv[2]) != 4){
  18. printf("\nError al introducir el numero de digitos del parametro 2\n");
  19. exit(-1);
  20. }
  21.  
  22. if( (dir=opendir(argv[1]))==NULL){
  23. printf("\nError en el primer open\n");
  24. exit(-1);
  25. }
  26.  
  27. octal = strtol(argv[2], ptr, 8);
  28.  
  29. struct stat atributos;
  30. int fd;
  31. while ((ent = readdir(dir)) != NULL){
  32. if( (strcmp(ent->d_name, ".")!=0) && (strcmp(ent->d_name, "..")!=0) ){
  33. if ( (fd = open(ent->d_name,O_RDONLY))<0){
  34. printf("\nError en el segundo open\n");
  35. exit(-1);
  36. }
  37.  
  38. printf("%s", ent->d_name);
  39. printf("%s", " : ");
  40.  
  41. if ( (stat(ent->d_name, &atributos)) <0){
  42. printf("\nError en stat\n");
  43. exit(-1);
  44. }
  45.  
  46. if( (atributos.st_mode & S_IRUSR) != 0)
  47. printf("%s", "r");
  48. else
  49. printf("%s", "-");
  50.  
  51. if( (atributos.st_mode & S_IWUSR) != 0)
  52. printf("%s", "w");
  53. else
  54. printf("%s", "-");
  55.  
  56. if( (atributos.st_mode & S_IXUSR) != 0)
  57. printf("%s", "x");
  58. else
  59. printf("%s", "-");
  60.  
  61. if( (atributos.st_mode & S_IRGRP) != 0)
  62. printf("%s", "r");
  63. else
  64. printf("%s", "-");
  65.  
  66. if( (atributos.st_mode & S_IWGRP) != 0)
  67. printf("%s", "w");
  68. else
  69. printf("%s", "-");
  70.  
  71. if( (atributos.st_mode & S_IXGRP) != 0)
  72. printf("%s", "x");
  73. else
  74. printf("%s", "-");
  75.  
  76. if( (atributos.st_mode & S_IROTH) != 0)
  77. printf("%s", "r");
  78. else
  79. printf("%s", "-");
  80.  
  81. if( (atributos.st_mode & S_IWOTH) != 0)
  82. printf("%s", "w");
  83. else
  84. printf("%s", "-");
  85.  
  86. if( (atributos.st_mode & S_IXOTH) != 0)
  87. printf("%s", "x");
  88. else
  89. printf("%s", "-");
  90.  
  91.  
  92.  
  93.  
  94. printf("%s", " ");
  95.  
  96. if( (chmod(ent->d_name, octal)) <0){
  97. printf("\nError en chmod\n");
  98. exit(-1);
  99. }
  100.  
  101.  
  102.  
  103. if( (atributos.st_mode & S_IRUSR) != 0)
  104. printf("%s", "r");
  105. else
  106. printf("%s", "-");
  107.  
  108. if( (atributos.st_mode & S_IWUSR) != 0)
  109. printf("%s", "w");
  110. else
  111. printf("%s", "-");
  112.  
  113. if( (atributos.st_mode & S_IXUSR) != 0)
  114. printf("%s", "x");
  115. else
  116. printf("%s", "-");
  117.  
  118. if( (atributos.st_mode & S_IRGRP) != 0)
  119. printf("%s", "r");
  120. else
  121. printf("%s", "-");
  122.  
  123. if( (atributos.st_mode & S_IWGRP) != 0)
  124. printf("%s", "w");
  125. else
  126. printf("%s", "-");
  127.  
  128. if( (atributos.st_mode & S_IXGRP) != 0)
  129. printf("%s", "x");
  130. else
  131. printf("%s", "-");
  132.  
  133. if( (atributos.st_mode & S_IROTH) != 0)
  134. printf("%s", "r");
  135. else
  136. printf("%s", "-");
  137.  
  138. if( (atributos.st_mode & S_IWOTH) != 0)
  139. printf("%s", "w");
  140. else
  141. printf("%s", "-");
  142.  
  143. if( (atributos.st_mode & S_IXOTH) != 0)
  144. printf("%s\n", "x");
  145. else
  146. printf("%s\n", "-");
  147.  
  148.  
  149.  
  150. close(fd);
  151. }
  152. }
  153.  
  154.  
  155. }
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?

Código
  1. #include<unistd.h>
  2. #include<sys/stat.h>
  3. #include<fcntl.h>
  4. #include<stdio.h>
  5. #include<errno.h>
  6. #include<sys/types.h>
  7. #include<dirent.h>
  8. #include<string.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. DIR *dir;
  13. struct dirent *ent;
  14. char **ptr;
  15. long octal;
  16.  
  17. if( strlen(argv[2]) != 4){
  18. printf("\nError al introducir el numero de digitos del parametro 2\n");
  19. exit(-1);
  20. }
  21.  
  22. if( (dir=opendir(argv[1]))==NULL){
  23. printf("\nError en el primer open\n");
  24. exit(-1);
  25. }
  26.  
  27. octal = strtol(argv[2], ptr, 8);
  28.  
  29. struct stat *atributos;
  30. int fd;
  31. while ((ent = readdir(dir)) != NULL){
  32. if( (strcmp(ent->d_name, ".")!=0) && (strcmp(ent->d_name, "..")!=0) ){
  33. if ( (fd = open(ent->d_name,O_CREAT|O_TRUNC|O_WRONLY,S_IRGRP|S_IWGRP|S_IXGRP))<0){
  34. printf("\nError en el segundo open\n");
  35. exit(-1);
  36. }
  37.  
  38. printf("%s", ent->d_name);
  39. printf("%s\n", " : ");
  40.  
  41. if ( (stat(ent->d_name, atributos)) <0){
  42. printf("\nError en stat\n");
  43. exit(-1);
  44. }
  45. chmod(ent->d_name, octal);
  46. close(fd);
  47. }
  48. }
  49.  
  50.  
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.
Código
  1. #include <iostream>
  2. #include <pthread.h>
  3. #include <semaphore.h>
  4. using namespace std;
  5.  
  6. const int num_items = 75 ;
  7. const int tam_vec = 15 ;
  8. int vector[tam_vec] ;
  9. int primera_libre = 0 ;
  10. int primera_ocupada = 0 ;
  11. sem_t puede_leer, puede_escribir ;
  12.  
  13.  
  14.  
  15. int producir_dato(){
  16.  
  17. int contador = 1 ;
  18. return contador++ ;
  19. }
  20.  
  21. void consumir_dato( int dato ){
  22.  
  23. cout << "dato recibido: " << dato << endl ;
  24. }
  25.  
  26.  
  27.  
  28. void * productor( void * ){
  29.  
  30. for( unsigned i = 0 ; i < num_items ; i++ ){
  31. if (primera_libre == tam_vec)
  32. primera_libre = 0;
  33. int dato = producir_dato() ;
  34. sem_wait (&puede_escribir);
  35. vector[primera_libre] = dato ;
  36. primera_libre++;
  37. sem_post(&puede_leer);
  38. }
  39. }
  40.  
  41. void * consumidor( void * ){
  42.  
  43. for( unsigned i = 0 ; i < num_items ; i++ ){
  44. int dato ;
  45. if (primera_ocupada == tam_vec)
  46. primera_ocupada = 0;
  47. sem_wait (&puede_leer);
  48. dato = vector[primera_ocupada] ;
  49. primera_ocupada++ ;
  50. sem_signal(&puede_escribir);
  51. consumir_dato( dato ) ;
  52. }
  53. }
  54.  
  55. int main(){
  56. pthread_t consumidora, productora;
  57. sem_init( &puede_leer, 0, 1);
  58. sem_init( &puede_escribir, 0 , 0);
  59.  
  60. pthread_create(&productora, NULL, productor, NULL);
  61. pthread_create(&consumidora, NULL, consumidor, NULL);
  62.  
  63. pthread_join( productora, NULL ) ;
  64.   pthread_join( consumidora, NULL ) ;
  65.  
  66. sem_destroy( &puede_escribir );
  67. sem_destroy( &puede_leer );
  68. }
5  Programación / Programación C/C++ / Re: Necesito ayuda urgente con hebras/hilos y semaforos en: 26 Octubre 2013, 15:45 pm
Ok. Era una tontería. No sabia que cuando compilabas había que poner -pthread.
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:

Código
  1. #include <iostream>
  2. #include <pthread.h>
  3. using namespace std ;
  4. void* proc1( void* arg )
  5. { for( unsigned long i = 0 ; i < 5000 ; i++ )
  6. cout << "hebra 1, i == " << i << endl ;
  7. return NULL ;
  8. }
  9. void* proc2( void* arg )
  10. { for( unsigned long i = 0 ; i < 5000 ; i++ )
  11. cout << "hebra 2, i == " << i << endl ;
  12. return NULL ;
  13. }
  14. int main()
  15. {
  16. pthread_t hebra1, hebra2 ;
  17. pthread_create(&hebra1,NULL,proc1,NULL);
  18. pthread_create(&hebra2,NULL,proc2,NULL);
  19. pthread_exit(NULL); // permite continuar a hebra1 y hebra2
  20. }


Y me da este error:
Código
  1. /tmp/ccPPYPph.o: En la función `main':
  2. ej.cpp:(.text+0xd7): referencia a `pthread_create' sin definir
  3. ej.cpp:(.text+0xf2): referencia a `pthread_create' sin definir
  4. collect2: error: ld devolvió el estado de salida 1
  5.  

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:

Código
  1. [fedora]
  2. name=Fedora $releasever - $basearch
  3. failovermethod=priority
  4. baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
  5. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
  6. enabled=1
  7. metadata_expire=7d
  8. gpgcheck=1
  9. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  10.  
  11. [fedora-debuginfo]
  12. name=Fedora $releasever - $basearch - Debug
  13. failovermethod=priority
  14. baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/
  15. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-debug-$releasever&arch=$basearch
  16. enabled=0
  17. metadata_expire=7d
  18. gpgcheck=1
  19. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  20.  
  21. [fedora-source]
  22. name=Fedora $releasever - Source
  23. failovermethod=priority
  24. baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/
  25. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=fedora-source-$releasever&arch=$basearch
  26. enabled=0
  27. metadata_expire=7d
  28. gpgcheck=1
  29. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  30.  

fedora-updates.repo:

Código
  1. [updates]
  2. name=Fedora $releasever - $basearch - Updates
  3. failovermethod=priority
  4. baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/
  5. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
  6. enabled=1
  7. gpgcheck=1
  8. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  9.  
  10. [updates-debuginfo]
  11. name=Fedora $releasever - $basearch - Updates - Debug
  12. failovermethod=priority
  13. baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/debug/
  14. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearch
  15. enabled=0
  16. gpgcheck=1
  17. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  18.  
  19. [updates-source]
  20. name=Fedora $releasever - Updates Source
  21. failovermethod=priority
  22. baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/SRPMS/
  23. #mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearch
  24. enabled=0
  25. gpgcheck=1
  26. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
  27.  
  28.  
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.  ;D
Y por si alguien le interesa, era lo que estaba dudando, una partición mal hecha.
9  Sistemas Operativos / GNU/Linux / Re: Ayuda con partición Ubuntu en: 13 Octubre 2013, 14:23 pm
Es posible que sea porque en realidad no hay ninguna partici'on creada.
Por favor ayudenme.
He estado usando virtualbox mucho tiempo, pero va muy lento y ya no lo aguanto.
10  Sistemas Operativos / GNU/Linux / Re: Ayuda con partición Ubuntu en: 13 Octubre 2013, 13:50 pm

Páginas: [1] 2 3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines