Foros del Web » Programación para mayores de 30 ;) » Programación General »

alguien sabe q hace esto?

Estas en el tema de alguien sabe q hace esto? en el foro de Programación General en Foros del Web. alguien sabe que hace este programa? me estoy volviendo loco #include <stdio.h> #include <stdlib.h> // for rand() #include <sys/types.h> #include <unistd.h> // for getpid() & ...
  #1 (permalink)  
Antiguo 24/04/2005, 08:48
 
Fecha de Ingreso: diciembre-2003
Mensajes: 190
Antigüedad: 20 años, 5 meses
Puntos: 0
alguien sabe q hace esto?

alguien sabe que hace este programa?
me estoy volviendo loco


#include <stdio.h>
#include <stdlib.h> // for rand()
#include <sys/types.h>
#include <unistd.h> // for getpid() & usleep()
#include <pthread.h>

#define MAX_THREADS 1000

char buffer[64];

void *collision(void *arg)
{
int i;
int id = *(int *)arg;

for (i = 0; i < sizeof(buffer) -1; i++)
{
buffer[i] = 'A' + id % ('Z' - 'A');
usleep(rand() % 9);
}
// printf("Hello world from node %d (thread id = 0x%x)\n", id, pthread_self());
return NULL;
}

int main(int argc, char* argv[])
{
int n, i;
pthread_t *threads;
int *ids;

if (argc != 2)
{
printf ("Usage: %s n\n where n is no. of threads\n", argv[0]);
return 1;
}

n = atoi(argv[1]);

if ((n < 1) || (n > MAX_THREADS))
{
printf ("The no of thread should be between 1 and %d.\n", MAX_THREADS);
return 1;
}

threads = (pthread_t *)malloc(n * sizeof(*threads));

ids = (int *)malloc(sizeof(int) * n);

for (i = 0; i < n; i++) // Start up threads
{
ids[i] = i;
pthread_create(&threads[i], NULL, collision, (void *)(ids + i));
}

for (i = 0; i < n; i++) // Synchronize the completion of each thread.
pthread_join(threads[i], NULL);
free(ids);
printf ("buffer = %s\n", buffer);
return 0;
}


muchas gracias
  #2 (permalink)  
Antiguo 24/04/2005, 08:58
Avatar de Eternal Idol  
Fecha de Ingreso: mayo-2004
Ubicación: Lucentum
Mensajes: 6.192
Antigüedad: 20 años
Puntos: 74
A grandes rasgos crea una cantidad de hilos, que especifique el usuario, que ejecutan la funcion collision.
__________________
¡Peron cumple, Evita dignifica! VIVA PERON CARAJO
  #3 (permalink)  
Antiguo 24/04/2005, 14:14
 
Fecha de Ingreso: diciembre-2003
Mensajes: 190
Antigüedad: 20 años, 5 meses
Puntos: 0
lo que queria saber es que hace la funcion colision
  #4 (permalink)  
Antiguo 24/04/2005, 15:07
 
Fecha de Ingreso: abril-2005
Mensajes: 4
Antigüedad: 19 años
Puntos: 0
devilish

hola como estan quiero crear un virus quien me explica
  #5 (permalink)  
Antiguo 24/04/2005, 15:08
 
Fecha de Ingreso: abril-2005
Mensajes: 4
Antigüedad: 19 años
Puntos: 0
Cita:
Iniciado por shadow devilish
hola como estan quiero crear un virus quien me explica
hihhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh hhhhhhhhhhhh
  #6 (permalink)  
Antiguo 24/04/2005, 15:09
 
Fecha de Ingreso: abril-2005
Mensajes: 4
Antigüedad: 19 años
Puntos: 0
[QUOTE=selma128]lo que queria saber es que hace la funcion colision[/QUOTEhola que tal me puedes explicar como crear un virus
  #7 (permalink)  
Antiguo 24/04/2005, 15:27
 
Fecha de Ingreso: abril-2005
Mensajes: 3.083
Antigüedad: 19 años
Puntos: 17
Spammer.......
  #8 (permalink)  
Antiguo 25/04/2005, 00:38
Avatar de Eternal Idol  
Fecha de Ingreso: mayo-2004
Ubicación: Lucentum
Mensajes: 6.192
Antigüedad: 20 años
Puntos: 74
id es el argumento que se le pasa a cada hilo (en este caso su 'numero' de orden de creacion).

Mientras i sea menor a 62 (buffer es un array de 64 bytes)
buffer[i] es igual a 'A' + el modulo de id sobre 'Z' - 'A'
ej. si id es 5 buffer[i] va a ser 'F'
porque A=65 + 5 % (25)=70 que en ASCII es 'F'

el usleep es para que espere.
__________________
¡Peron cumple, Evita dignifica! VIVA PERON CARAJO
  #9 (permalink)  
Antiguo 25/04/2005, 06:00
 
Fecha de Ingreso: diciembre-2003
Mensajes: 190
Antigüedad: 20 años, 5 meses
Puntos: 0
muchas gracias Ethernal, eres un crack para todo esto de llos lenguaje de programacion


un saludo
  #10 (permalink)  
Antiguo 25/04/2005, 06:43
Avatar de Eternal Idol  
Fecha de Ingreso: mayo-2004
Ubicación: Lucentum
Mensajes: 6.192
Antigüedad: 20 años
Puntos: 74
De nadas y gracias

Eternal Idol
__________________
¡Peron cumple, Evita dignifica! VIVA PERON CARAJO
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:55.