ITEM: AJ9998L
How to check print q status from C program?
Question:
        How can I check the status of a print queue within a
        C program to test whether a print queue is DOWN, READY,
        and so on?
Response:
ACT:
        You will need to open the file:
                /var/spool/lpd/stat/s.\.\
        The 3rd byte of this file contains the information that
        you are looking for, but to do it the right way,
        read sizeof(struct stfile) bytes from this file into
        a struct of type stfile (defined in /usr/include/IN/stfile.h)
        Then, you can check the value of the s_status field of the
        stfile struct and compare against one of the constants
        defined in backend.h such as RUNNING, etc.
\#include \
\#include \
\#include \
int main()
{       /* File that has status for this print queue */
        FILE *status_file;
        /* All info about a print queue status is in a stfile struct */
        struct stfile status;
        /* The 1st and last byte of the stfile structure */
        char *first, *last;
        status_file = fopen("/var/spool/lpd/stat/s.queuename.queudevice",
                                 "r");
        /* Read sizeof(struct stfile) bytes from stat file into status */
        first = (char *)&status;
        last = first + sizeof(struct stfile);
        while (first \< last) 
                *(first++) = fgetc(status_file);
        /* Print the status found in byte 3 of the structure
           This will be 1 for an enabled queue, 4 for a disabled
           or DOWN queue as defined in backend.h
        */
        printf("%d", status.s_status); 
Support Line: How to check print q status from C program? ITEM: AJ9998L
Dated: June 1995 Category: N/A
This HTML file was generated 99/06/24~13:30:27
Comments or suggestions?
Contact us