From owner-freebsd-questions@FreeBSD.ORG Fri Nov 25 21:30:06 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org 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 E0DD016A41F for ; Fri, 25 Nov 2005 21:30:06 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from smtp-out3.blueyonder.co.uk (smtp-out3.blueyonder.co.uk [195.188.213.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id B129D43D46 for ; Fri, 25 Nov 2005 21:30:04 +0000 (GMT) (envelope-from xfb52@dial.pipex.com) Received: from [80.192.2.225] ([80.192.2.225]) by smtp-out3.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.6713); Fri, 25 Nov 2005 21:30:56 +0000 Message-ID: <4387825A.4040307@dial.pipex.com> Date: Fri, 25 Nov 2005 21:30:02 +0000 From: Alex Zbyslaw User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-GB; rv:1.7.12) Gecko/20051106 X-Accept-Language: en MIME-Version: 1.0 To: freebsd-questions@freebsd.org, gerard@seibercom.net References: <20051125153642.2B05.GERARD@seibercom.net> In-Reply-To: <20051125153642.2B05.GERARD@seibercom.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 25 Nov 2005 21:30:56.0640 (UTC) FILETIME=[8561D000:01C5F207] Cc: Subject: Re: Viewing Programs Running From CRON 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, 25 Nov 2005 21:30:07 -0000 Gerard Seibert wrote: >I have asked many dumb questions before, and this will no doubt add to >the list. > >Scenario: > >I start a program from CRON. As an example, let us use >/sysutils/portmanager. Now this program is being run in the background. >How do I get it to run in the foreground so that I can view what it is >doing, and or stop it if I want to? If I succeed in that maneuver, can I >place it in the background again? > > I'm not aware of any way to do what you are asking, though maybe it can be done though /proc, I'm not sure. See man procfs if you want to experiment. Instead, why don't you make the cron job redirect output to a file e.g. /sysutils/portmanager 2>&1 | tee /tmp/portmanager That way you can do a tail -f on /tmp/portmanager and still get the output mailed you as normal. If you don't want to be mailed the output then just use > in place of | tee. If more than one such job might run at once then you'll have to find some way to name the file differently for each run. Calling it /tmp/portmanager.$$ would probably work as each invocation should be run using a different shell process. I haven't tested this :-( --Alex PS Background isn't really an accurate description of the process running from cron. What you are trying to do is to see STDOUT and STDERR from some process which is unrelated to the interactive shell you are running. A background process, as you've probably come across it, is a process run from your shell but which doesn't stop you interacting with the shell. In this case the shell is able to send STDOUT and STDERR from the process to your terminal, but the job run from cron has no such terminal. A better description would be a daemon. Probably not explained very well, and no doubt someone can correct the details.