From owner-freebsd-questions Tue Apr 28 11:48:55 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA00171 for freebsd-questions-outgoing; Tue, 28 Apr 1998 11:48:55 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from mail-gw3.pacbell.net (mail-gw3.pacbell.net [206.13.28.55]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA00148 for ; Tue, 28 Apr 1998 11:48:39 -0700 (PDT) (envelope-from psh1@cornell.edu) Received: from wartch.rih.org (ppp-207-214-209-1.snfc21.pacbell.net [207.214.209.1]) by mail-gw3.pacbell.net (8.8.8/8.7.1+antispam) with ESMTP id LAA09039 for ; Tue, 28 Apr 1998 11:48:38 -0700 (PDT) Received: from wartch.rih.org (localhost [127.0.0.1]) by wartch.rih.org (8.8.8/8.8.8) with ESMTP id LAA03181 for ; Tue, 28 Apr 1998 11:47:39 -0700 (PDT) (envelope-from psh1@cornell.edu) Message-Id: <199804281847.LAA03181@wartch.rih.org> To: freebsd-questions@FreeBSD.ORG Subject: system() and pthreads From: Peter Haight Reply-To: psh1@cornell.edu Date: Tue, 28 Apr 1998 11:47:39 -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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