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

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Sistemas Operativos
| |-+  GNU/Linux (Moderador: MinusFour)
| | |-+  creacion de thread en linux desde c
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: creacion de thread en linux desde c  (Leído 1,597 veces)
JAHVEM13

Desconectado Desconectado

Mensajes: 2


Ver Perfil
creacion de thread en linux desde c
« en: 15 Octubre 2013, 23:06 pm »

Hola gente si me pueden dar una mano muchas gracias  :
como puedo controlar la creación de hilos (para ejecutar uno y poder seguir en la consola como pasa en el caso 1 con firefox)
les pongo el código .. alguna sugerencia 

#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void func1(void)
{  printf("\n\tSoy el thread que ejecuta gimp %d",pthread_self());
   system("gimp");
   pthread_exit(0);
 }
           
 void func2(void)
 {
    printf("\n\tSoy el thread que ejecuta firefox %d\n",pthread_self() );
    system("firefox");
    pthread_exit(0);
 }
 void func3 (void)
  {   
     printf("\n\tSoy el thread que ejecuta yast%d",pthread_self());
     system("yast");
     pthread_exit(0);
  }
           
   void func4(void)
  {
     printf("\n\tSoy el thread que ejecuta cheese\n",pthread_self());               
     system("cheese");
     pthread_exit(0);
  }
             

int main(int argc, char *argv[])
{
        pid_t pid;  // pid_t es de tipo nativo de unix ,es como un entero
        pid  = fork();
   
    pthread_t h1,h2,h3,h4;
   
         if(pid < 0) // error
        {
            printf("Error al crear proceso hijo,\n");
            return (-1);
        }
        if(pid == 0)  //creacion del proceso hijo
        {
          //printf("\n\tSoy el hijo y mi PID es :%d \n", getpid());
     
        }
        else
        {
          int opcion;
    printf("\n\n\tMENU DE OPCIONES\n");
    printf("\n\t-------------------------");
    printf("\n\t1-> thread que ejecuta gimp");
    printf("\n\t2-> thread que ejecuta firefox");
    printf("\n\t3-> thread que ejecuta yast");
    printf("\n\t4-> thread que ejecuta Cheese\n\r");
    scanf("%d",&opcion);
    printf("\n\t usted eligio la opcion %d \n",opcion);
   
    //if(opcion < 1 || opcion > 4)
        //VerMenu();
     
    if(opcion >= 1 || opcion <= 4){
     switch (opcion)
 {
   case 1:
    {       pthread_create(&h1, NULL,(void*)func1, NULL);
            pthread_join(h1,NULL);
      break;
    }       

   case 2:
    {       pthread_create(&h2, NULL,(void*)func2, NULL);
            pthread_join(h2,NULL);
      break;
    }
   case 3:
    {      pthread_create(&h3, NULL,(void*)func3, NULL);
           pthread_join(h3,NULL);
      break;
    }
   case 4:
     {      pthread_create(&h4, NULL,(void*)func4, NULL);
            pthread_join(h4,NULL);
       break;
     }
        }
    }
   }
   return 0;
}
void EjecutarHilos(int *opcion)
{ /*
   pthread_t h1,h2,h3,h4;

  switch (*opcion)
 {
   case 1:
    {       pthread_create(&h1, NULL,(void*)func1, NULL);
            pthread_join(h1,NULL);
      break;
    }       

   case 2:
    {       hread_create(&h2, NULL,(void*)func2, NULL);
            pthread_join(h2,NULL);
      break;
    }
   case 3:
    {      hread_create(&h3, NULL,(void*)func3, NULL);
           pthread_join(h3,NULL);
      break;
    }
   case 4:
     {      hread_create(&h4, NULL,(void*)func4, NULL);
            pthread_join(h4,NULL);
       break;
     }
}
void VerMenu()
{
    int opcion;
    printf("\n\n\tMENU DE OPCIONES\n");
    printf("\n\t-------------------------");
    printf("\n\t1-> thread que ejecuta gimp");
    printf("\n\t2-> thread que ejecuta firefox");
    printf("\n\t3-> thread que ejecuta yast");
    printf("\n\t4-> thread que ejecuta Cheese");
    scanf("%d",&opcion);
   
    if(opcion < 1 || opcion > 4)
        VerMenu();
    else
       EjecutarHilos(&opcion);
  */
}


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ayuda acceder a contol desde thread en otra clase
.NET (C#, VB.NET, ASP)
Fr4NN^ 0 2,210 Último mensaje 9 Mayo 2009, 10:58 am
por Fr4NN^
¿Qué esta mal con esta creacion de HILO (Thread)?
Programación C/C++
yovaninu 3 3,010 Último mensaje 18 Septiembre 2011, 11:41 am
por Eternal Idol
[Android] Modificar ImageView desde un thread
Java
Nephewless 0 1,366 Último mensaje 29 Septiembre 2012, 18:16 pm
por Nephewless
Beep desde thread, new + delete
Programación C/C++
patilanz 2 1,633 Último mensaje 24 Agosto 2015, 01:54 am
por patilanz
Problemas al insertar imagen desde un Thread
Java
Luis Daniel 1 1,995 Último mensaje 15 Junio 2018, 04:38 am
por Damian616
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines