# How to get Running or queued Job parameter using python library?

**URL:** <https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130>\
**Category:** Users/Site Administrators\
**Created:** [May 29, 2025, 4:09pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130 "2025-05-29T16:09:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahuhem](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sahuhem](https://community.openpbs.org/u/sahuhem)\
**Post date:** [May 29, 2025, 4:09pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/1 "2025-05-29T16:09:11Z")

</div>

Suppose my running jobs are as given below

#qstat -aw

ip-10-77-173-99:  
Req’d Req’d Elap  
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time

* * *

222.ip-10-77-173-99 sahuhem dcv Custom\_DCV\_Sess 7644 1 1 – 70:00 R 05:43

I want to get the job Quename using python pbs library. How can i do that  
I tried below but it gives error.

> > > pbs.server().job(‘222’).queue()  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > File “/opt/pbs/lib/python/altair/pbs/v1/\_svr\_types.py”, line 710, in job  
> > > return pbs\_statobj(“job”, jobid, self.\_connect\_server)  
> > > File “/opt/pbs/lib/python/altair/pbs/v1/\_svr\_types.py”, line 234, in pbs\_statobj  
> > > vo = getattr(pr, r)  
> > > AttributeError: ‘pbs\_resource’ object has no attribute ‘myhpc\_cunit’

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [May 29, 2025, 6:11pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/2 "2025-05-29T18:11:45Z")

</div>

a quick clarification : using hooks or you want to get it programaticaly using python + pbs libraries (to create client command of your own).

---

<div class="post-metadata">

**Author:** ![sahuhem](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sahuhem](https://community.openpbs.org/u/sahuhem)\
**Post date:** [May 30, 2025, 8:52am UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/3 "2025-05-30T08:52:49Z")

</div>

Mainly I want to get it programaticaly using python + pbs libraries.

Also appreciate if you can provide a hook script.

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [May 31, 2025, 7:06pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/4 "2025-05-31T19:06:40Z")

</div>

You can print the queuename in the $PBS\_HOME/server\_logs/YYYYMMDD using this queuejob event hook

```auto
import pbs

e = pbs.event()
j = e.job

if ( hasattr(j.queue, "name")) :
    pbs.logmsg(pbs.LOG_ERROR, "queue has name %s" % j.queue.name)
else :
    j.queue = pbs.server().queue(str(pbs.server().default_queue))
    pbs.logmsg(pbs.LOG_ERROR, "queue has name %s" % j.queue.name)

```

You can use the PBS IFL library and write a c program to interace witht he PBS Server to get the queue name :  
Ref: [https://help.altair.com/2024.1.0/PBS%20Professional/PBSProgramGuide2024.1.pdf](https://help.altair.com/2024.1.0/PBS%20Professional/PBSProgramGuide2024.1.pdf)

Sample code:jobqueuename.c

```auto
#include <stdio.h>
#include <stdlib.h>
#include <pbs_ifl.h>

int main(int argc, char *argv[]) {
    int connect;
    struct batch_status *job_status;
    struct attrl *attr;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <job_id>\n", argv[0]);
        return 1;
    }

    // Connect to PBS server
    connect = pbs_connect(NULL); // NULL = default server
    if (connect < 0) {
        perror("pbs_connect");
        return 1;
    }

    // Get full status of the job
    job_status = pbs_statjob(connect, argv[1], NULL, NULL);
    if (!job_status) {
        perror("pbs_statjob");
        pbs_disconnect(connect);
        return 1;
    }

    // Search for 'queue' attribute
    for (attr = job_status->attribs; attr; attr = attr->next) {
        if (strcmp(attr->name, ATTR_queue) == 0) {
            printf("Job %s is in queue: %s\n", argv[1], attr->value);
            break;
        }
    }

    // Clean up
    pbs_statfree(job_status);
    pbs_disconnect(connect);
    return 0;
}

```

```auto
source /etc/pbs.conf
locate libpbs.so.0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/pbs/lib
gcc -o jobqueuename jobqueuename.c -I/opt/pbs/include -L/opt/pbs/lib -lpbs
./jobqueuename 
Usage: ./jobqueuename <job_id of the running job>
./jobqueuename 145
Job 145 is in queue: workq

```

You can extend the code to your requirements and following the progamming guide.

---

<div class="post-metadata">

**Author:** ![sahuhem](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sahuhem](https://community.openpbs.org/u/sahuhem)\
**Post date:** [June 2, 2025, 11:33am UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/5 "2025-06-02T11:33:06Z")

</div>

is there any equivalent python script as that of “jobqueuename.c” ?

---

<div class="post-metadata">

**Author:** ![adarsh](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@adarsh](https://community.openpbs.org/u/adarsh)\
**Post date:** [June 2, 2025, 7:43pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/6 "2025-06-02T19:43:45Z")

</div>

Please check this

> [@Pbs\_ifl access from python](https://community.openpbs.org/t/pbs-ifl-access-from-python/1118):
>
> I’m trying to use pbs\_ifl routines from python, but keep running into deadends. I started with a git clone of 18, configured it (with a private --prefix), built it (with some hacking involved due to missing RPMs), and installed the pieces that built. Now running pbs\_python via: env PYTHONPATH=$HOME/PBS\_18/lib/python/altair \ LD\_LIBRARY\_PATH=$HOME/PBS\_18/lib \ $HOME/PBS\_18/bin/pbs\_python --hook -i hook.input I get: pbs\_python: No such file or directory (2) in pbs\_python\_ext\_alloc\_python\_scri…

---

<div class="post-metadata">

**Author:** ![speleolinux](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@speleolinux](https://community.openpbs.org/u/speleolinux)\
**Post date:** [June 3, 2025, 6:54am UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/7 "2025-06-03T06:54:36Z")

</div>

Hi Hemanta

For an example of writing Python code to get PBS info see my script here:  
‘[GitHub - UTS-eResearch/pbsweb: Web interface to show nodes, queues and jobs on a High Performance Compute Cluster using PBS Pro](https://github.com/UTS-eResearch/pbsweb)’  
There are some simple examples under the tests directory. The only tricky bit is getting the pbs object file created to import into your Python code.  
Mike

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [June 4, 2025, 1:14am UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/8 "2025-06-04T01:14:37Z")

</div>

Since that request, I have come up with a simpler way to access PBS IFL routines from python. See the github project:

> **[GitHub - drtoss/pyqs: Python versions of PBS qstat, pbs\_rstat, and pbsfs](https://github.com/drtoss/pyqs)**
>
> Python versions of PBS qstat, pbs\_rstat, and pbsfs

Of interest is the build\_pbs\_ifl script that builds \_pbs\_ifl.so and pbs\_ifl.py.

Example use to show queue of job:

```auto
$ cat tt.py
#!/usr/bin/env python3
import pbs_ifl as ifl
c = ifl.pbs_connect('')
bs = ifl.pbs_statjob(c, None, None, None)
for job in bs:
    print(job['id'], job['queue'])
ifl.pbs_disconnect(c)

$ ./tt.py
3000.rhserver workq

```

---

<div class="post-metadata">

**Author:** ![sahuhem](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sahuhem](https://community.openpbs.org/u/sahuhem)\
**Post date:** [June 4, 2025, 6:56am UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/9 "2025-06-04T06:56:28Z")

</div>

Thanks for the update. However, I found below error

[root@e22c7dfa2a97607 sahuhem]# /usr/bin/env python3  
Python 3.9.20 (main, Sep 26 2024, 20:59:47)  
[GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] on linux  
Type “help”, “copyright”, “credits” or “license” for more information.

> > > import sys  
> > > import os  
> > > sys.path.append(f’/opt/pbs/lib/python/‘)  
> > > sys.path.append(f’/opt/pbs/lib/python/altair’)  
> > > import pbs  
> > > import pbs\_ifl as ifl  
> > > c = ifl.pbs\_connect(‘’)  
> > > bs = ifl.pbs\_statjob(c, None, None, None)  
> > > print (bs)  
> > > \<pbs\_ifl.batch\_status; proxy of \<Swig Object of type ‘batch\_status \*’ at 0x7ff60f6a6fc0\> \>

---

<div class="post-metadata">

**Author:** ![dtalcott](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/dtalcott/32/410_2.png) [@dtalcott](https://community.openpbs.org/u/dtalcott)\
**Post date:** [June 4, 2025, 9:04pm UTC](https://community.openpbs.org/t/how-to-get-running-or-queued-job-parameter-using-python-library/4130/10 "2025-06-04T21:04:53Z")

</div>

> [@sahuhem](#):
>
> print (bs)  
> \<pbs\_ifl.batch\_status; proxy of \<Swig Object of type ‘batch\_status \*’ at 0x7ff60f6a6fc0\> \>

That’s not an error. It just means that python has no method to display a “batch\_status” object, so it just tells you its address.

If you want to see what’s in bs, convert it to a list:

```auto
   print(list(bs))

```
