0

How can I know my job number when executing a COBOL program through a shell script?

  • What shell are you using? Also an an example of how you start the script and what the script contents are could help. – Anthon Nov 5 '13 at 10:50
  • @Anthon - looks like Bash basead on the tag. – slm Nov 5 '13 at 10:55
  • 1
    @slm - Duh, I normally only forget to look at the title of a post... %-) – Anthon Nov 5 '13 at 11:16
  • @Anthon - I often miss them too 8-) – slm Nov 5 '13 at 11:17
2

Can you explain a little bit more what you're doing? There are several "numbers" related to your program.

NOTE: In my examples the dollar sign ($) denotes the command prompt and isn't meant to be typed as part of the command.

  1. Process ID

    When a program runs in Unix it's assigned a process ID. Say I have the program sleep, and I run it for 100 seconds.

    $ sleep 10000
    

    I can then find out its process ID using the command ps. The process ID would be 9263, for example:

    $ ps -eaf|grep sleep
    saml      9263  5736  0 05:48 pts/1    00:00:00 sleep 10000
    
  2. Backgrounded job

    When a program is backgrounded, it can continue running without being directly connected to the shell from where it was executed.

    $ sleep 10000 &
    [1] 9370
    

    Here I'm runnning the program sleep for 10000 seconds. The ampersand (&) at the end tells the shell to background it. When jobs are backgrounded they'reassigned a job #. In this case it was assigned job # 1. The 9370 is the process ID.

    We can find out what jobs are running using the jobs command:

    $ jobs
    [1]+  Running                 sleep 10000 &
    

    We can use the job # to act on this process either by killing it, or bringing it back into the foreground.

    $ kill %1
    
    $ fg
    -or-
    $ fg %1
    
  3. at and batch commands

    There are additional places where "numbers" show up in a job # capacity. Scheduled tasks that are queued up using the commands at or batch are also assigned numbers.

    $ at -f mycrontest.sh  10pm tomorrow
    job 14 at Sun Jul  8 22:00:00 2007
    
  4. Compute clustering technologies

    Further still, if you're site is using a clustering technology such as Grid Scheduler/Grid Engine, SLURM, or others, these systems too have job #'s assigned to each individual task.

0
#!/bin/bash

cobol_program &
echo "The COBOL program is running in the background with PID: $!"

See the man page for bash under 'Special Parameters'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.