0

I'm trying to use pthreads to create two new processes which each use a file descriptor to either read or write from a pipe.

I have a main function which forks itself and executes the pthread creator using execl(). From there, I run pthreads to create two processes which each get a different end of a pipe. I then wait for the threads to finish, then keep doing other things.

Here's my code:

int createThreads(int fds[])
{
    int retcd = OK;  /* return code */
    pthread_t talk1, talk2;
    int ret1, ret2;

    // Create both talk agent processes
    ret1 = pthread_create(&talk1, NULL, talk, &fds[0]); // read
    ret2 = pthread_create(&talk2, NULL, talk, &fds[1]); // write

    // Wait for both processes to finish at the same time
    pthread_join(talk1, NULL);
    pthread_join(talk2, NULL);

    return(retcd);
}

The talk function takes the file descriptor and does some stuff with it. The problem is, when I run ps -f u [username] I can't seem to see the two pthreads processes spawn. Is there something wrong with the syntax?

1
  • 2
    man ps Commented Feb 1, 2014 at 23:15

1 Answer 1

2

pthread_create does not create new processes - it creates new threads in the same process. If you want to see threads in ps you need to use H option - like ps H -fu [username].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.