From owner-freebsd-hackers@FreeBSD.ORG Mon Jul 23 09:15:27 2007 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E6B7E16A418 for ; Mon, 23 Jul 2007 09:15:27 +0000 (UTC) (envelope-from mux@freebsd.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id D401913C457 for ; Mon, 23 Jul 2007 09:15:27 +0000 (UTC) (envelope-from mux@freebsd.org) Received: by elvis.mu.org (Postfix, from userid 1920) id E791B1A4D81; Mon, 23 Jul 2007 01:48:10 -0700 (PDT) Date: Mon, 23 Jul 2007 10:48:10 +0200 From: Maxime Henrion To: Garrett Cooper Message-ID: <20070723084810.GE44455@elvis.mu.org> References: <46A46910.9080901@u.washington.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46A46910.9080901@u.washington.edu> User-Agent: Mutt/1.4.2.3i Cc: hackers@freebsd.org Subject: Re: How do I daemonize a process? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2007 09:15:28 -0000 Garrett Cooper wrote: > As the subject suggests I'm trying to determine how I can daemonize > a C process, outside of using the rc infrastructure, so that it won't > exit when the TTY exists. Does anyone know any quick references or examples? > Thanks, > -Garrett The proper way to do this is to use the setsid() function. If it is somehow not available on one of your target system, some people use a hack which consists in calling fork() two times to daemonize the process; that is supposed to work too. Cheers, Maxime