# Force PBS job to stay in queue until conditions are met

**URL:** <https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760>\
**Category:** Users/Site Administrators\
**Created:** [November 17, 2017, 1:54am UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760 "2017-11-17T01:54:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmmmm](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmmmm](https://community.openpbs.org/u/mmmmm)\
**Post date:** [November 17, 2017, 1:54am UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/1 "2017-11-17T01:54:51Z")

</div>

Hello -

New PBS user here. I’d like to know how I can prevent a job to run until all conditions are met.  
**Here is an example**

I want to submit a job which requires 5 application licenses, but currently only 3 licenses are available.  
I have 100 CPUs available on my my queue, and my job require only 10.

Given these infos, my job could be started in PBS, but it will be waiting for the application license to be available.

Instead I want my job to stay Queued (even if I have enough CPU available) until the number of available application licenses are 5.

Any idea how I can do that?

---

<div class="post-metadata">

**Author:** ![jon](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/jon/32/23_2.png) [@jon](https://community.openpbs.org/u/jon)\
**Post date:** [November 17, 2017, 9:59pm UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/2 "2017-11-17T21:59:28Z")

</div>

I recommend that you look at server\_dyn\_res and dynamic resources in the admin guide

---

<div class="post-metadata">

**Author:** ![mmmmm](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmmmm](https://community.openpbs.org/u/mmmmm)\
**Post date:** [November 18, 2017, 11:20pm UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/3 "2017-11-18T23:20:33Z")

</div>

Hi Jon -

Thank for your reply. I looked at “server\_dyn\_res” and it seems to be what I’m looking for. Not sure how to implement it yet, but it seems to be a good starting point.

Thanks !

---

<div class="post-metadata">

**Author:** ![pcebull](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/pcebull/32/83_2.png) [@pcebull](https://community.openpbs.org/u/pcebull)\
**Post date:** [November 20, 2017, 8:11pm UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/4 "2017-11-20T20:11:14Z")

</div>

As Jon said, we use a server\_dyn\_res to check for licenses. In our sched\_config we have this line for Abaqus:

server\_dyn\_res: “abq\_lic !/var/spool/PBS/flexlm/abq\_chk.py”

The abq\_chk.py basically queries the license server with a “lmstat -a” command and returns the number of licenses available. Once you define a resource called “abq\_lic”, the user can then submit a job with “-l abq\_lic=12”, for example, and the job won’t be scheduled until 12 abaqus licenses are available.

---

<div class="post-metadata">

**Author:** ![mmmmm](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmmmm](https://community.openpbs.org/u/mmmmm)\
**Post date:** [November 22, 2017, 2:39am UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/5 "2017-11-22T02:39:26Z")

</div>

**EDIT** :  
tl;dr: I created a new line on my .que file (and not append to existing PBS -l nodes=1:ppn=8 and it worked!

* * *

Hey guys -

Thanks a lot for your help.

I added `server_dync_res` on my `sched_config`:

```auto
server_dyn_res: “my_test_var !/path/to/my/bash”

```

and also updated the `resourcedef` with:

```auto
my_test_var type=float flag=h

```

my\_test\_var is the output of a basic bash script which return the number of licenses available.

I have restarted PBS but it looks like I’m still missing something.  
I tried to submit my job using `qsub myJob.que -l my_test_var=500`  
No matter what value I specify for my\_test\_var, the job will always run.

I looked at the .que file and noticed I already have a -l parameter:

```auto
#!/bin/sh -f 
#PBS -N myjob
#PBS -V -j oe -o myjob.qlog
#PBS -m ae
#PBS -q myqueue
#PBS -l nodes=1:ppn=8
cd $PBS_O_WORKDIR
echo "HELLO WORLD"

```

II tried to add

```auto
#PBS -l nodes=1:ppn=8:my_test_var=500

```

But this time I’m getting an error when submitting the job:

```auto
qsub: node(s) specification error

```

If I remove my\_test\_variable, then the job will start. So I tried to just change the order to be:

```auto
#PBS -l my_test_var=500:nodes=1:ppn=8

```

This time I’m getting

```auto
qsub: Illegal attribute or resource value Resource_List.my_test_var under resources: 

```

So I went back to PBS doc and noticed I have to also specify this variable to sched\_config

```auto
resources: "my_test_var,ncpus, etc etc ..." 

```

Restarted PBS … but I’m setting getting the same problem.

I guess I need to specify my\_test\_var somewhere else on PBS config but I haven’t been able to figure out where.

Any pointers?

---

<div class="post-metadata">

**Author:** ![bhroam](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.openpbs.org/bhroam/32/20_2.png) [@bhroam](https://community.openpbs.org/u/bhroam)\
**Post date:** [November 22, 2017, 7:01pm UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/6 "2017-11-22T19:01:14Z")

</div>

A few things first:  
I would suggest not using the -lnodes format of requesting a job. This is a very old selection format that has not been used in about 10 years. Use the new select/place format. It is much more robust. The conversion of -lnodes=1:ppn=8 is -lselect=1:ncpus=8 -lplace=scatter.

Following that, the flag=h on the resource means that the resource only belongs in the select statement. This is incompatible with a server\_dyn\_res. A server\_dyn\_res should have no flags. It’s for job wide resources. If you want select/node level resources, look into using a mom periodic hook to send these resources to the server for the scheduler to use.

One more thing, The option to request resources is -l (little ell), not cap L.

So with all that taken into account, I think you did the right thing in the wrong order. You need to request -lmy\_test\_var=500. This didn’t work for you in the beginning because you didn’t have my\_test\_var in the sched\_config resources line. You did add my\_test\_var to the resources line later on, but didn’t try this request again.

I hope this helps,  
Bhroam

---

<div class="post-metadata">

**Author:** ![mmmmm](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmmmm](https://community.openpbs.org/u/mmmmm)\
**Post date:** [December 20, 2017, 12:04am UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/7 "2017-12-20T00:04:27Z")

</div>

Hi Guys -

Thanks for your help. Everything works good, I just have one additional question for this ressource allocation.

I have configured 2 queues (low\_priority and high\_priority)

Say I have 3 jobs, 2 LOW currently running and 1 HIGH on pending.

My HIGH job is not suspending any LOW jobs because I don’t have enough licenses available. That said, suspending a LOW job would free up enough license for my HIGH priority job to run. But for whatever reason my scheduler is not smart enough to determine that (note if I have enough license, HIGH suspend LOW as expected)

It that something I can configure using server\_dyn ?

---

<div class="post-metadata">

**Author:** ![Abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@Abc](https://community.openpbs.org/u/Abc)\
**Post date:** [June 7, 2018, 9:59am UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/8 "2018-06-07T09:59:14Z")

</div>

Hi Guys,

“lmstat -a” command returns a huge output.  
Is there any bash script to get the available license from this output?

---

<div class="post-metadata">

**Author:** ![mmmmm](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mmmmm](https://community.openpbs.org/u/mmmmm)\
**Post date:** [June 7, 2018, 5:03pm UTC](https://community.openpbs.org/t/force-pbs-job-to-stay-in-queue-until-conditions-are-met/760/9 "2018-06-07T17:03:11Z")

</div>

@Abc - I just use sed  
ex:  
lmutil lmstat -a -c $SERVER | grep “Users of $FEATURE” | sed -e ‘s/._Total of(._)licenses in use.\*/\1/’
