From owner-freebsd-questions Thu Apr 30 11:30:09 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA23794 for freebsd-questions-outgoing; Thu, 30 Apr 1998 11:30:09 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from mail-gw6.pacbell.net (mail-gw6.pacbell.net [206.13.28.41]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA23713 for ; Thu, 30 Apr 1998 11:30:03 -0700 (PDT) (envelope-from psh1@cornell.edu) Received: from wartch.rih.org (ppp-207-214-209-74.snfc21.pacbell.net [207.214.209.74]) by mail-gw6.pacbell.net (8.8.8/8.7.1+antispam) with ESMTP id LAA02689 for ; Thu, 30 Apr 1998 11:30:02 -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 LAA03082 for ; Thu, 30 Apr 1998 11:29:31 -0700 (PDT) (envelope-from psh1@cornell.edu) Message-Id: <199804301829.LAA03082@wartch.rih.org> To: freebsd-questions@FreeBSD.ORG Subject: Threads and system() From: Peter Haight Reply-To: psh1@cornell.edu Date: Thu, 30 Apr 1998 11:29:31 -0700 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I might have posted this already, but I didn't get any replies. I'm not on the list, so I don't know whether my earlier post showed up. By the way, is there anyway to check that? I tried searching for my post, but it wasn't there. How soon do the articles become searchable in the archive? The problem I'm having is that I have this threaded program in which I want to launch an external editor using the system() call. This works fine until the system() call returns. When the call returns, that thread finishes its stack and then exits. When that thread exits, my whole program exits. The rest of my program should be in a permanent while() loop. What's going on here. Is this correct behavior? Am I doing something wrong? Here's an example program that illustrates this: #include #include #include void signal_received(int arg) { printf("signal %d\n", arg); } 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; } Here's how I compile it: gcc thread.c -lc_r The program totally exits after printing out my .cshrc and 'Hello!'. If I take out the system() call, it will run indefinitely. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message