Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
¿Cómo espero la salida de sysfs?

Intenté lo obvio (ver más abajo), pero no detecta nuevos resultados en /var/log/syslog. Estoy seguro de que ya hay una respuesta en alguna parte, pero no he podido encontrarla.

Aquí está mi código (mi mejor suposición de cómo hacer esto):

 #include <stdio.h> #include <stdlib.h> // provides fopen() #include <unistd.h> // provides sleep() int main() { // *** This is failing to pick up new output on /var/log/syslog. I'm not sure // how to do this properly. // Open a read file handle on /sys/kernel/tracing/trace and wait for data to // appear there. When it does, echo it to the screen. This is essentially an // implementation of "tail -f /sys/kernel/tracing/trace". //FILE *fp = fopen("/sys/kernel/tracing/trace", "r"); FILE *fp = fopen("/var/log/syslog", "r"); char c; if (fp != NULL) { printf("Opened the file successfully. Waiting...\n"); } else { printf("Failed to open the file.\n"); exit(1); } // Check every second and output whatever is in the buffer. while(1) { c = fgetc(fp); // We get back -1 when there is nothing to read. if (c != -1) { printf("%c", c); } else { printf("."); fflush(stdout); sleep(1); } } fclose(fp); return 0; }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Debe llamar a clearerr(fp) para borrar el indicador feof:

 // Check every second and output whatever is in the buffer. while(1) { c = fgetc(fp); // We get back -1 when there is nothing to read. if (c != -1) { printf("%c", c); } else { printf("."); fflush(stdout); if(feof(fp)) clearerr(fp); // <-- clear the feof indicator sleep(1); } }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda