Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Apr 1998 11:47:39 -0700
From:      Peter Haight <psh1@cornell.edu>
To:        freebsd-questions@FreeBSD.ORG
Subject:   system() and pthreads
Message-ID:  <199804281847.LAA03181@wartch.rih.org>

next in thread | raw e-mail | index | archive | help

I have an application I'm writing which uses threads. What I want to do is
fork off an external program from a thread. I want that thread to wait till
the program is done and then continue. I can't seem to get this to work.
In fact, when I run this, the entire program exits after I see the 'Hello!'.
I feel like I'm missing something fundamental here. Can anyone give me an
example of how I can do this? 

Thanks.

Here is the program:

void* run_system(void* arg)
{
    system("cat /home/peterh/.cshrc");
    printf("Hello!\n");
}

int main()
{
    pthread_t thread;
    pthread_attr_t thread_attr;
    int result;

    while (1)
    {
        result = pthread_attr_init(&thread_attr);
        printf("pthread_attr_init returned %d\n", result);
        result = pthread_create(&thread, &thread_attr, &run_system, 0);
        printf("pthread_create returned %d\n", result);
        sleep(5);
    }

    return 0;
}



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199804281847.LAA03181>