The shepherd

The shepherd is the instance in Grid Engine, that starts and controls a job. It

Process Flow

Initialization

The following actions are taken to initialize the shepherd (see source/clients/shepherd.c:  main):

Setting up the job environment

A job runs in a defined process environment. This process environment comprises of environment variables, limits, special parallel processing environments, security settings etc.

In addition to the standard setup procedure, scripts can be defined to be executed as prolog/epilog for the job and as setup/shutdown procedure for parallel environments.

Other components of the job environment can be:

This process environment is setup in source/daemons/shepherd/shepherd.c: main

Running the job

A job is executed as a child process of the shepherd process. During the runtime of the job, the shepherd parent process controls its child and may send signals to the child process.

The job's startup contains the following steps (see source/daemons/shepherd/shepherd.c: start_child):

  • If the job has been checkpointed previously and shall now be rerun, a checkpoint restart method is setup.
  • Fork a child process that will execute the job.
  • The parent waits for the child to exit, if any signals have to be delivered to the job, the parent process sends these signals to the process group of its child process.
  • The child process starts up the job (see source/daemons/shepherd/builtin_starter.c: son and source/daemons/shepherd/builtin_starter.c: start_command):
  • After a job exits, job information is spooled in the job's spool directory for further use by the execution daemon containing:

    Cleaning up the job environment

    After a job has terminated, the job is cleaned up: The process environment is cleaned up in source/daemons/shepherd/shepherd.c: main

    Communication with the execd - spooled files

    The Shepherd and the execution daemon share some information by writing spool files .

    The execution daemon passes information like the jobs configuration and the environment to shepherd (see for example source/daemons/execd/exec_job.c: sge_exec_job),
    the shepherd reports information like the jobs exit code and usage information back to the execution daemon (see for example source/daemons/shepherd/shepherd.c: wait_my_child).

    The spool files are located in a host specific spool directory (usually $SGE_ROOT/default/spool/<hostname>). The spool directory can be defined in the cluster configuration - see parameter execd_spool_dir in the cluster configuration, sge_conf(5).

    Under the host specific spool directory, a subdirectory active_jobs is created by the execd, for each job, the execd creates a subdirectory <jobid>.<taskid> that holds the job specific spool files.
    If the job is a parallel job with a tight integration, this job specific spool directory is created on each execution host involved in the execution of the job, for each task a subdirectory <petaskid> is created that holds the task specific spool files.

    The following spool files exist in Grid Engine:

    If the job is a parallel job, the following additional files are created
     

    Communication with qlogin/qrsh

    Interactive jobs submitted using qlogin or qrsh require additional communication between shepherd and the qlogin/qrsh client command - see also documentation of qrsh.

    Qlogin/qrsh sets up a socket and writes the port address to an environment variable "QRSH_PORT" in the format "<host>:<port>" (see source/clients/qsh/qsh.c: main).

    The shepherd connects to this port and sends the following information to the qlogin/qrsh client: