1 year ago

#300493

test-img

goxarad784

How many process and thread does this code create?

int main( ) {
  pid t pid1, pid2;
  pid1 = fork ( );
  pid2 = fork ( );
  if (pid1 == 0) { /* child process */
    pthread_create (. . .);
  }
  if (pid2 > 0) { /* parent process */
    pthread_create (. . .);
  }
}

I think it creates 8 processes.

  if (pid2 > 0) { /* parent process */
    pthread_create (. . .);
  }

I am not sure about the number of threads though. Does each thread have child with pid 0 and pid greater than 0, so 16 threads?

c

multithreading

fork

pid

0 Answers

Your Answer

Accepted video resources