From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 16 23:56:55 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9BF3116A4B3 for ; Tue, 16 Sep 2003 23:56:55 -0700 (PDT) Received: from firecrest.mail.pas.earthlink.net (firecrest.mail.pas.earthlink.net [207.217.121.247]) by mx1.FreeBSD.org (Postfix) with ESMTP id DD6F843FDD for ; Tue, 16 Sep 2003 23:56:52 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from user-2ivfm4d.dialup.mindspring.com ([165.247.216.141] helo=mindspring.com) by firecrest.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 19zWF6-0005gt-00; Tue, 16 Sep 2003 23:56:49 -0700 Message-ID: <3F68055D.E1094799@mindspring.com> Date: Tue, 16 Sep 2003 23:55:25 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Mike Durian References: <200309161647.38197.durian@boogie.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a49e1eecc99db1b47ae7bdf2bc9c648ec1a2d4e88014a4647c350badd9bab72f9c350badd9bab72f9c cc: hackers@freebsd.org Subject: Re: tty layer and lbolt sleeps X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Sep 2003 06:56:55 -0000 Mike Durian wrote: > I'm trying to implement a serial protocol that is timing sensitive. > I'm noticing things like drains and reads and blocking until the > next kernel tick. I believe this is due to the lbolt sleeps > in the tty.c code. > > It looks like I can avoid these sleeps if isbackground() returns > false, however I can't figure out how to make this happen. The > process is running in the foreground and my attempts to play > with the process group haven't helped. > > Can anyone explain what is happening and nudge me towards a fix? You need your process to become a process group leader, and then you need the serial port you are interested in to become the controlling tty for your process. The first is accomplished with setpgid(2); the second is accomplished with setsid(2) and open(2) (the open must not specify O_NOCTTY). You can move around after that by calling tcsetpgrp(3). You can only have one controlling tty per process, so if you wanted to, for example, have a terminal emulation program that would quit when you turned off your terminal (on-to-off transition of DTR) *and* you *also* wanted it to receive SIGHUP when you got an on-to-off DCD transition from a modem, you would need two processes. See also the source code for getty(8) and the library utility function login_tty(3). -- Terry