Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 May 2000 09:21:44 -0500
From:      Dan Nelson <dnelson@emsphone.com>
To:        Chris Dillon <cdillon@wolves.k12.mo.us>
Cc:        Konrad Heuer <kheuer@gwdu60.gwdg.de>, Lorenzo Iania <l.iania@sintesi.net>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: PROBLEM FOUND (sort of): Re: lpr: order of print requests
Message-ID:  <20000503092144.B27366@dan.emsphone.com>
In-Reply-To: <Pine.BSF.4.20.0005030746200.1907-100000@mail.wolves.k12.mo.us>; from "Chris Dillon" on Wed May  3 07:56:34 GMT 2000
References:  <20000502174713.A14919@dan.emsphone.com> <Pine.BSF.4.20.0005030746200.1907-100000@mail.wolves.k12.mo.us>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (May 03), Chris Dillon said:
> On Tue, 2 May 2000, Dan Nelson wrote:
> > Aha.  Yes, it _does_ do FIFO, but if you look at the source, the
> > queue sorting routine simply sorts on stat(mtime) of the queue
> > file, so jobs submitted in the same second will sort randomly.  A
> > quick fix would be to sleep for 1 second between "lpr" calls.
> 
> That isn't the problem.  You can sleep as much as you want between
> submitting the print jobs and the job order still gets munged.  Even

If this is the case, then using mtime at all is wrong.  You sure
waiting 1 second between submissions doesn't work?

> a job that at one time had #1 rank gets inverted and ends up with the
> lowest rank.  I even modified common.c (a shot in the dark, I had no
> idea what I was doing, really) to check for modtime with
> st_mtimespec.tv_nsec for nsec modtime resolution, and that didn't
> change the behaviour any.

I checked, and fstat() always puts zeros in the nsec fields, either
because ffs doesn't store them, or for some other reason.
 
> It appears that qsort() is the culprit.  In fact, here is an excerpt
> from the manpage:
> 
>     The functions qsort() and heapsort() are not stable, that is, if
>     two mem- bers compare as equal, their order in the sorted array
>     is undefined.  The function mergesort() is stable.

This doesn't help, since you can't guarantee that the files are in
order in the directory, either.  I think someone posted a better
solution, which would be sorting by mtime, and when mtime is identical,
sort by job number in the filename.

You can't simply sort by filename because that would break "lpc topq".
 
-- 
	Dan Nelson
	dnelson@emsphone.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000503092144.B27366>