fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <pthread.h>
  5. #include <syslog.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/sysinfo.h>
  9. #include <sched.h>
  10.  
  11. void *thread_function(void *arg) {
  12. openlog(NULL, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
  13. syslog(LOG_INFO, "[COURSE:1][ASSIGNMENT:1] Hello World from Thread!");
  14. closelog();
  15. pthread_exit(NULL);
  16. }
  17.  
  18. int main() {
  19. openlog(NULL, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
  20.  
  21. // Print uname -a output to syslog
  22. FILE *uname_output = popen("uname -a", "r");
  23. if (uname_output) {
  24. char buffer[256];
  25. while (fgets(buffer, sizeof(buffer), uname_output) != NULL) {
  26. strtok(buffer, "\n"); // Removing trailing newline character
  27. syslog(LOG_INFO, "[COURSE:1][ASSIGNMENT:1] %s", buffer);
  28. }
  29. pclose(uname_output);
  30. }
  31.  
  32. syslog(LOG_INFO, "[COURSE:1][ASSIGNMENT:1] Hello World from Main!");
  33.  
  34. pthread_t thread;
  35. pthread_create(&thread, NULL, thread_function, NULL);
  36. pthread_join(thread, NULL);
  37.  
  38. closelog();
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5296KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Standard output is empty