From owner-freebsd-questions Sat Mar 1 14:22:49 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2079337B406 for ; Sat, 1 Mar 2003 14:22:47 -0800 (PST) Received: from smtp.acd.net (smtp.acd.net [207.179.102.146]) by mx1.FreeBSD.org (Postfix) with ESMTP id 566AA43F85 for ; Sat, 1 Mar 2003 14:22:46 -0800 (PST) (envelope-from taxman@ACD.NET) Received: from 207.179.77.42 ([207.179.77.42]) by smtp.acd.net with Microsoft SMTPSVC(5.0.2195.5329); Sat, 1 Mar 2003 17:22:46 -0500 From: taxman To: Mike Meyer , Cliff Sarginson Subject: Re: single user mode Date: Fri, 28 Feb 2003 17:01:31 -0500 User-Agent: KMail/1.5 Cc: FreeBSD Questions References: <20030227202359.GA4488@raggedclown.net> <15967.41747.67024.941224@guru.mired.org> In-Reply-To: <15967.41747.67024.941224@guru.mired.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200302281701.31777.taxman@acd.net> X-OriginalArrivalTime: 01 Mar 2003 22:22:46.0896 (UTC) FILETIME=[16273700:01C2E041] Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Friday 28 February 2003 12:57 pm, Mike Meyer wrote: > Since nobody else stepped forward with an answer, I'll try.... > > In <20030227202359.GA4488@raggedclown.net>, Cliff Sarginson typed: > > No I can think of kludgy ways to do this, but I want to know the way > > it should be done. How can you tell from with a shell script whether you > > are in single-user mode or not ? > > The difference between starting single-user and starting multi-user is > that init just starts a shell in one case, and in the other it runs > /etc/rc then deals with /etc/ttys. Shutting down to single-user shuts > down the things in /etc/ttys - and anything else - then launches a > shell. There doesn't appear to be a way to ask init if it's running > in single-user or multi-user mode. > > I'd say the best way is to look for a shell process with a ppid of > 1. This can be fooled by having a shell started in /etc/ttys. Looking > for things to be running in multi-user mode depends on them running, > which may fail during (ab)normal system operation. > > > Might I suggest that you're not really worried about being > single-user, but instead worried about some condition that is usually > true in single-user mode (quiescent file systems, no network daemons, > etc)? If that's the case, you'd probably be better off checking that > condition than checking for single-user mode. After all, given any > assumption you make about single-user mode, I can violate that > assumption if I really want to. Mike, good points. I don't think there is an elegant way of doing it either. To that end I don't think there is a truly important distinction anyway. If you're just looking for the simple answer, Cliff, checking if you can switch to another virtual terminal, and looking at the output of ps and perhaps mount, should tell you which one you're in. Presuming you get use to the output of those commands in both scenarios. Tim To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message