Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > Sco Unix

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-15-2008, 05:23 PM
Rob S
 
Posts: n/a
Default Sleep command quitting

Hi,

For many years we've used a little workaround to hold a serial port open, to
allow us to cat large print jobs to a serial printer.

The command is put into /etc/rc.d/8/userdef:

(stty 9600 ixon ixoff -ixany ; while : ; do sleep 3600; done) < /dev/ttya1 &

It runs fine on bootup, but since OS507 (not sure which MP if any first showed
the problem), the sleep command simply stops of its own accord after a time.

On all older versions of SCO OS from 500 upwards, this command stays running for
as long as the system is up.

Any ideas what's causing it to terminate, or another way of doing the same
thing?

thanks
-Rob
robatwork at mail dot com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-15-2008, 05:23 PM
Bob Bailin
 
Posts: n/a
Default Re: Sleep command quitting


"Rob S" <robatworkDeleteTheseFourWords@mail.com> wrote in message
news:432a9c89.26582515@giganews.nildram.co.uk...
> Hi,
>
> For many years we've used a little workaround to hold a serial port open, to
> allow us to cat large print jobs to a serial printer.
>
> The command is put into /etc/rc.d/8/userdef:
>
> (stty 9600 ixon ixoff -ixany ; while : ; do sleep 3600; done) < /dev/ttya1 &
>
> It runs fine on bootup, but since OS507 (not sure which MP if any first showed
> the problem), the sleep command simply stops of its own accord after a time.
>
> On all older versions of SCO OS from 500 upwards, this command stays running for
> as long as the system is up.
>
> Any ideas what's causing it to terminate, or another way of doing the same
> thing?


It might be catching a quit or intr signal from the serial port. Try adding a
trap "" 1 2 3
to the subshell, or
-isig
to the stty command.
If that still fails, enclose the whole thing in another while : ; do ( ... ) ; done &
loop.

Bob


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-15-2008, 05:24 PM
Bela Lubkin
 
Posts: n/a
Default Re: Sleep command quitting

Rob S wrote:

> For many years we've used a little workaround to hold a serial port open, to
> allow us to cat large print jobs to a serial printer.
>
> The command is put into /etc/rc.d/8/userdef:
>
> (stty 9600 ixon ixoff -ixany ; while : ; do sleep 3600; done) < /dev/ttya1 &
>
> It runs fine on bootup, but since OS507 (not sure which MP if any first showed
> the problem), the sleep command simply stops of its own accord after a time.
>
> On all older versions of SCO OS from 500 upwards, this command stays running for
> as long as the system is up.
>
> Any ideas what's causing it to terminate, or another way of doing the same
> thing?


It cannot be that the `sleep` command is terminating. If that were the
case, the shell loop would just start another one. It has to be that
the shell loop is somehow terminating.

That script was popular when I started working at SCO Support in 1989.
The reason for the loop was that the `sleep` binary in some old release
of Xenix (old in 1989) only supported sleep arguments up to some limited
number, probably 32767. As I remember it, even in 1989, the then-
current Xenix `sleep` supported a 32-bit argument.

Try changing to:

(stty 9600 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya1 &

2 billion seconds is about 63 years. If the system stays up that long
and someone has to figure out why the ancient serial printer goes wrong,
I'll owe you a nice dinner. ;-}

Taking out the loop simplifies things a lot. The printer's continuing
settings no longer depend on the shell to keep waking up and executing
that loop. In fact, the shell is smart enough in this situation to
"exec" the final sleep -- the shell process disappears, so you have one
less purposeless process (per printer) sitting around in the system.

<deep_background>

Another thing that might not be clear about this sort of holdopen
script: it doesn't really hold the settings you specify. Holding a port
open prevents the driver from resetting its settings back to the driver
defaults. But that initial `stty` command exerts no ongoing force. If
anything else comes along and makes further changes, the holdopen script
holds _those_ settings. That is:

(stty 9600 < /dev/tty123; sleep 10000000) &
# tty123 is now set to 9600 for the next 4 months
# two hours later:
stty 4800 < /dev/tty123
# the `stty 4800` process ends immediately
# but its effects remain: tty123 is now at 4800 for the next 4 months

Most of the OSR5 printer interface scripts do their own `stty` commands,
so the holdopen script is mainly serving to retain _those_ settings from
one printout to the next. Without a holdopen script, the port would sit
at the driver's default settings most of the time, except when a
printout was in progress.

Some versions of the holdopen look more like this:

(while :; do stty 9600 ixon ixoff -ixany; sleep 3600; done) < /dev/ttya1 &

Putting the `stty` inside the loop means that its settings _do_
occasionally get slammed onto the port -- whether or not a print job is
currently active. This could either have no effect (if the interface
script is leaving those settings in effect, or if it's using compatible
ones); or disastrous effect (suppose the interface script -- and the
printer, of course -- is actually using 19200 bps). Or it could have a
mysterious effect (maybe the interface script actually uses hardware
flow control, and the printer has buggy XON/XOFF that sends ^S to
throttle input but forgets to send ^Q to continue it. The print jobs
will usually work OK, but once in a while the hour will be up, the
holdopen will poke in XON/XOFF settings, and the printer will suddenly
lock up...)

Finally, you don't need a separate holdopen script for each printer.
One process can hold open a large number of file descriptors. It's
clumsy to hold more than 7 open in a single shell script, though, so
it's easier to reduce the number of holdopen processes by a factor of 7
than it is to drop all the way down to one system-wide holdopen process.

Change this:

(stty 9600 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya1 &
(stty 4800 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya2 &
(stty 19200 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya3 &

to this:

exec 3</dev/ttya1 4</dev/ttya2 5</dev/ttya3
stty 9600 ixon ixoff -ixany < /dev/ttya1
stty 4800 ixon ixoff -ixany < /dev/ttya2
stty 19200 ixon ixoff -ixany < /dev/ttya3
exec sleep 2000000000

The first line uses Bourne shell syntax to open the three ttys. Those
file descriptors will remain open as long as the shell (or any child it
has passed them to) is running. Then we apply the various initial
settings, knowing that they'll "stick" because we're holding open the
ports. Finally, we go to sleep "forever".

The shell's syntax only allows single-digit file descriptor numbers
here, and it's simpler if we don't mess with fds 0-2. That's why we're
limited to 7 per holdopen script. A trivial C program could do
hundreds.

</deep_background>

>Bela<

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-15-2008, 05:24 PM
Rob S
 
Posts: n/a
Default Re: Sleep command quitting

On 15 Sep 2005 16:43:00 -0400, Bela Lubkin <filbo@armory.com> wrote:

<lots of fantastic detail snipped>

What can I say other than Wow!

I shall give them a go - thanks very much


-Rob
robatwork at mail dot com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-15-2008, 05:24 PM
Bill Vermillion
 
Posts: n/a
Default Re: Sleep command quitting

In article <200509151342.aa23956@deepthought.armory.com>,
Bela Lubkin <filbo@armory.com> wrote:


>Finally, you don't need a separate holdopen script for each printer.
>One process can hold open a large number of file descriptors. It's
>clumsy to hold more than 7 open in a single shell script, though, so
>it's easier to reduce the number of holdopen processes by a factor of 7
>than it is to drop all the way down to one system-wide holdopen process.
>
>Change this:


> (stty 9600 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya1 &
> (stty 4800 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya2 &
> (stty 19200 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya3 &


>to this:
>
> exec 3</dev/ttya1 4</dev/ttya2 5</dev/ttya3
> stty 9600 ixon ixoff -ixany < /dev/ttya1
> stty 4800 ixon ixoff -ixany < /dev/ttya2
> stty 19200 ixon ixoff -ixany < /dev/ttya3
> exec sleep 2000000000


When I used to use the scripts a long time ago, I used a separate
sleep value for each instantiation. Thus when I had problems I
knew which 'sleep' task to kill in the ps output as I could
see the different sleep number.

Bill
--
Bill Vermillion - bv @ wjv . com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-15-2008, 05:24 PM
Rick Palen
 
Posts: n/a
Default Re: Sleep command quitting

bv@wjv.com (Bill Vermillion) wrote in news:IMwxny.At3@wjv.com:

> In article <200509151342.aa23956@deepthought.armory.com>,
> Bela Lubkin <filbo@armory.com> wrote:
>
>
>>Finally, you don't need a separate holdopen script for each printer.
>>One process can hold open a large number of file descriptors. It's
>>clumsy to hold more than 7 open in a single shell script, though, so
>>it's easier to reduce the number of holdopen processes by a factor of
>>7 than it is to drop all the way down to one system-wide holdopen
>>process.
>>
>>Change this:

>
>> (stty 9600 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya1 &
>> (stty 4800 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya2 &
>> (stty 19200 ixon ixoff -ixany; sleep 2000000000) < /dev/ttya3 &

>
>>to this:
>>
>> exec 3</dev/ttya1 4</dev/ttya2 5</dev/ttya3
>> stty 9600 ixon ixoff -ixany < /dev/ttya1
>> stty 4800 ixon ixoff -ixany < /dev/ttya2
>> stty 19200 ixon ixoff -ixany < /dev/ttya3
>> exec sleep 2000000000

>
> When I used to use the scripts a long time ago, I used a separate
> sleep value for each instantiation. Thus when I had problems I
> knew which 'sleep' task to kill in the ps output as I could
> see the different sleep number.
>
> Bill



Another way to do it (and it might even be older than '89, I can't
remember!) is to use a process like cat to keep the ports open.

(stty ixon ixoff; cat >/dev/null ) </dev/ttya1 &

We always put these in /etc/rc.d/8/userdef. If a support site
called with garbage on their printers, we always told them that
their cat died

Bela's way with exec sleep 2000000000 is better but I just give
this for some historical context.

Rick
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-15-2008, 05:24 PM
Rob S
 
Posts: n/a
Default Re: Sleep command quitting

On Fri, 16 Sep 2005 14:29:10 GMT, Rick Palen <rickpalen@hotmail.com> wrote:

-We always put these in /etc/rc.d/8/userdef. If a support site
-called with garbage on their printers, we always told them that
-their cat died

Our customers are notoriously humourless, but I may try that!


-Rob
robatwork at mail dot com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-15-2008, 05:24 PM
Bela Lubkin
 
Posts: n/a
Default Re: Sleep command quitting

Rick Palen wrote:

> Another way to do it (and it might even be older than '89, I can't
> remember!) is to use a process like cat to keep the ports open.
>
> (stty ixon ixoff; cat >/dev/null ) </dev/ttya1 &
>
> We always put these in /etc/rc.d/8/userdef. If a support site
> called with garbage on their printers, we always told them that
> their cat died
>
> Bela's way with exec sleep 2000000000 is better but I just give
> this for some historical context.


Actually I'd say your way is better. Any length of `sleep` could
eventually time out. Your `cat` has a different termination condition
-- receiving EOF on the tty. Which is highly unlikely if there's
actually a printer attached to it.

It would be even better if there was an input source which the kernel
guaranteed to allow you to open, but which never produced any input.
Similar to /dev/null, but it should never return from read() instead of
always returning EOF.

But for this purpose, one of the printer ports would suffice.

One reason the `cat` might be better is that you can lard it with extra
arguments which will show up in `ps -ef`:

exec </dev/ttya1 3</dev/ttya2 4</dev/ttya3
stty 9600 ixon ixoff -ixany < /dev/ttya1
stty 4800 ixon ixoff -ixany < /dev/ttya2
stty 19200 ixon ixoff -ixany < /dev/ttya3
exec cat - Holdopen script for ttya1, a2, a3

Now I'm using fd 0 (stdin) for the first printer port; shell syntax lets
us use that plus fds 3-9, so now we can do 8 per script. (We could
probably also use fds 1 & 2, but it's safer not to.)

>Bela<

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-15-2008, 05:24 PM
Ian Peattie
 
Posts: n/a
Default Re: Sleep command quitting

In article <200509161033.aa15294@deepthought.armory.com>, Bela Lubkin <filbo@armory.com> wrote:

>One reason the `cat` might be better is that you can lard it with extra
>arguments which will show up in `ps -ef`:


I seem to recall that in the past you could do the same thing with `sleep`,
until someone 'fixed' it to complain about the extra argument rather than
ignore it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-15-2008, 05:24 PM
Tony Lawrence
 
Posts: n/a
Default Re: Sleep command quitting

Bela Lubkin wrote:
> Rick Palen wrote:
>
>
>>Another way to do it (and it might even be older than '89, I can't
>>remember!) is to use a process like cat to keep the ports open.
>>
>> (stty ixon ixoff; cat >/dev/null ) </dev/ttya1 &
>>
>>We always put these in /etc/rc.d/8/userdef. If a support site
>>called with garbage on their printers, we always told them that
>>their cat died
>>
>>Bela's way with exec sleep 2000000000 is better but I just give
>>this for some historical context.

>
>
> Actually I'd say your way is better. Any length of `sleep` could
> eventually time out. Your `cat` has a different termination condition
> -- receiving EOF on the tty. Which is highly unlikely if there's
> actually a printer attached to it.
>
> It would be even better if there was an input source which the kernel
> guaranteed to allow you to open, but which never produced any input.
> Similar to /dev/null, but it should never return from read() instead of
> always returning EOF.
>
> But for this purpose, one of the printer ports would suffice.
>
> One reason the `cat` might be better is that you can lard it with extra
> arguments which will show up in `ps -ef`:
>
> exec </dev/ttya1 3</dev/ttya2 4</dev/ttya3
> stty 9600 ixon ixoff -ixany < /dev/ttya1
> stty 4800 ixon ixoff -ixany < /dev/ttya2
> stty 19200 ixon ixoff -ixany < /dev/ttya3
> exec cat - Holdopen script for ttya1, a2, a3
>
> Now I'm using fd 0 (stdin) for the first printer port; shell syntax lets
> us use that plus fds 3-9, so now we can do 8 per script. (We could
> probably also use fds 1 & 2, but it's safer not to.)
>
>
>>Bela<


I think I'd rather keep 'em separate. If I need to screw with one port,
I can kill its process and not affect the others.

And I think I'd still wrap the whole thing in a "while" - I know the
printer shouldn't send an eof back to me, but sometimes people do go
killing processes they don't recognize, so the "while" would rejuvenate
the cat. Of course they could kill the shell too, but mostly they won't.



--
Tony Lawrence
Unix/Linux/Mac OS X resources: http://aplawrence.com
Geek Yard Sale: http://geekyardsale.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:01 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603