[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20030916: pqutil race condition



Arthur,

I think I've figured-out pqutil(1)'s behavior.

>Date: Tue, 16 Sep 2003 09:33:49 -0400 (EDT)
>From: "Arthur A. Person" <address@hidden>
>Organization: Penn State University
>To: Steve Emmerson <address@hidden>
>Subject: Re: 20030915: pqutil race condition 

The above message contained the following:

> I'm going to eliminate the -r and -v since they seem unrelated to the
> problem.
> 
> If I run
> 
>    pqutil -w /usr/local/ldm/pq/ldm.pq
> 
> manually, as a command, I get normal output and low cpu usage.
> 
> If I run
> 
>    pqutil -w /usr/local/ldm/pq/ldm.pq >& junk.log &

I assume that ">& junk.log" means that your user-shell will redirect both
standard output and standard error to the file "junk.log".  Please let
me know if this is incorrect.

> manually, I get:
> 
> [1]  + Suspended (tty output)        pqutil -w /usr/local/ldm/pq/ldm.pq >& 
> junk.log

pqutil(1) is intended for interactive use, so it tries to read
user-commands from standard input.  This causes it to receive a SIGTSTP
when your user-shell executes it in the background.

> 
> on my terminal screen and no activity (0 bytes) in the output junk.log
> file.

That is as it should be because it's suspended due to the SIGTSTP 
awaiting user-input.

> If I run from a script file
> 
> #!/bin/csh
> pqutil -w /usr/local/ldm/pq/ldm.pq >& junk.log &
> 
> I get normal output in the junk.log file, but the pqutil process takes
> large amounts of cpu (50-100%).  I've been starting the program from a
> script, which I didn't think would be a problem, but apparently there's
> some problem related to starting it this way.

Starting pqutil(1) asynchronously from a script results in the pqutil(1)
processes becoming orphaned (i.e., your user-shell is no longer the
parent process).

Because orphaned processes have no controlling terminal, pqutil(1)'s
attempt to read user-input fails every time with great rapidity and the
resulting tight loop eats up the CPU.

pqutil(1) will have to be modified to support the way you want to use it.

If you're interested, you might try modifying the file "src/pq/pqutil.c"
by changing

    status = pq_sequence(pq, TV_GT, clssp, display_watch, 0);

    if (status == 0)
        continue;
    else if (status == PQUEUE_END){
        udebug("End of queue");
        break;
    }

to

    status = pq_sequence(pq, TV_GT, clssp, display_watch, 0);

    if (status == 0)
        continue;
    else if (status == PQUEUE_END){
        udebug("End of queue");
        pq_suspend(1);
        break;
    }

If you try the above, please let me know how it works.

> 
>                                     Art.
> 
> Arthur A. Person
> Research Assistant, System Administrator
> Penn State Department of Meteorology
> email:  address@hidden, phone:  814-863-1563

Regards,
Steve Emmerson