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

157
Vistas
Will processes be blocked, if the number of child processes greater than processors while using pipeline?

My program stops running while the number of child processes is big. I do not know what the problem could be, but I guess the child processes are somehow blocked while running.

Here is the main workflow of the program:

void function(int process_num){

    int i;

    // initial variables for fork()
    int status = 0;
    pid_t child_pid[process_num], wpid;
    int *fds = malloc(sizeof(int) * process_num * 2);

    // initial pipes 
    for(i=0; i<process_num; i++){
        if(pipe(fds + i*2) <0)
            exit(0);
    }

    // start child processes to write
    for(i=0; i<process_num; i++){
        child_pid[i] =fork();

        if(child_pid[i] == 0){
            close(fds[i*2]);
            // do something ...
            // write(fds[i*2+1], something);
            close(fds[i*2+1]);
            exit(0);
        }else if(child_pid[i] == -1){
            printf("fork error\n");
            exit(0);
        }
    }

    // parent waits child processes and reads
    for(i=0; i<process_num; i++){

      pid_t cpid = waitpid(child_pid[i], &status, 0);
      if (WIFEXITED(status)){
        close(fds[i*2+1]);
        // do something ...
        // read(fds[i*2], something);
       close(fds[i*2]);
      }
    }
    free(fds);
    while((wpid = wait(&status)) > 0);
}

I checked the status of processes via htop, there were several (e.g. 8 while process_num was 110) child processes left with state S.

and now comes my question: if the number of child processes is greater than the number of processors, will the child processes be blocked while using pipeline for child processes and present process to communicate (parent process waits until all child processes executed)? Thanks a lot!

EDIT: I printed the Id of fds when using read() and write(), and I found that the read began at 4 and write at 5, I have no idea why was it the case, does somebody know that?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The number of processors has no impact here. The operating system is alive, able to run any process that has something to do. This is a pure software problem, all processes are in sleep state (S) waiting for some event that never happens.

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