From owner-freebsd-questions@FreeBSD.ORG Fri Nov 6 17:31:15 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D2334106568B for ; Fri, 6 Nov 2009 17:31:15 +0000 (UTC) (envelope-from usleepless@gmail.com) Received: from mail-fx0-f227.google.com (mail-fx0-f227.google.com [209.85.220.227]) by mx1.freebsd.org (Postfix) with ESMTP id 5E5EC8FC14 for ; Fri, 6 Nov 2009 17:31:14 +0000 (UTC) Received: by fxm27 with SMTP id 27so312016fxm.3 for ; Fri, 06 Nov 2009 09:31:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=M0lViBA+9oxzu3RpgplUeJJMpmUBncOW2XLkAcc4G+c=; b=CG7aJHuRJc6MJOj/L9N1eATuMrxB7GrBwOHmQ3iccIj76r7KwQiyEEnFRaoQHmyTqS RH1I0g2iSUwgG09MDLGKgnJIa+gzU4tg5hpYDNGrj6tpnbX8QLkgsLws2AOxcuRAyhmf RS2bt2mkkrFYuI7swJlnNpY1+p2dXRroXRlkI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=rG4s0QGZm1swi35fASJZ42pUj8Z+9IXc1rWkWGy9ZIdhDlYyowvwfTs7QY6ah0g6P7 negKSxQ2/Nl7kRPajNjdtsKRE0WVjjhxZIkaVRS26FVzhq2kQDEHGlck1tYxQcPyexTs lEXeKtPdjSRXUWjs3TnJsWqGghShI7lTu+4x8= MIME-Version: 1.0 Received: by 10.204.160.86 with SMTP id m22mr4923042bkx.82.1257528674161; Fri, 06 Nov 2009 09:31:14 -0800 (PST) In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB3394EDDF@MBX03.exg5.exghost.com> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D117F@MBX03.exg5.exghost.com> <4AEC5E02.8040705@FreeBSD.org> <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D11A9@MBX03.exg5.exghost.com> <200911040149.48701.mel.flynn+fbsd.questions@mailing.thruhere.net> <7B9397B189EB6E46A5EE7B4C8A4BB7CB3394ED41@MBX03.exg5.exghost.com> <7B9397B189EB6E46A5EE7B4C8A4BB7CB3394EDDF@MBX03.exg5.exghost.com> Date: Fri, 6 Nov 2009 18:31:14 +0100 Message-ID: From: usleepless@gmail.com To: Peter Steele Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: "freebsd-questions@freebsd.org" Subject: Re: system() call causes core dump X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Nov 2009 17:31:15 -0000 On Fri, Nov 6, 2009 at 5:52 PM, Peter Steele wrote: > >I am following this thread since i find it interesting ( playing around > with popen & threads at times ). > > > >I am still trying to understand what Kris said. He says it is not safe to > fork from a multithread proces. And he suggests using execve. > > > >You stacktrace btw is consistent with what Kris says: "and if that thread > tries to acquire a lock or other formerly-shared resource it may deadlock or > crash, because the child process is > >no longer accessing the same memory location as the threads in the parent > process". -> that's probably the spinlock in malloc. > > This is why we switched to vsys/vfork, assuming it would effectively do the > same thing as execve. Perhaps not not. I can give it a try. I am still > curious though why only this one particular system call is causing a crash. > We have many calls running in other threads and none have ever caused a > problem. They all do the same thing, run a command and save the output in a > file, and then we process the output. The only thing different is the > command we run in this case-fstat. > Actually, i have just read the implementation of system() ( /usr/src/lib/libc/system.c ), It does fork() and then execl(). So my suggestion is not going to work. Then i read some of the malloc code ( /usr/src/lib/libstd/malloc.c ). It uses spinlocks alright, and they need to be initialized. My guess is that are not reinitialized in your forked process. I have no clue how to fix that. Another thought was that your application is compiled as multithreaded, but fstat, grep etc are probably not. But from what i can see, they use the same malloc implementation. I think the crash in the malloc is from a malloc in fstat or grep ( there is no malloc in system() ). regards, usleep > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to " > freebsd-questions-unsubscribe@freebsd.org" >