# include "pantasks.h"

int kill_job (int argc, char **argv) {

  Job *job;
  int JobID;

  if (argc < 2) {
    gprint (GP_ERR, "USAGE: kill (JobID)\n");
    return (FALSE);
  }
  JobID = atoi (argv[1]);

  job = FindJob (JobID);
  if (job == NULL) {
    gprint (GP_LOG, "job not found\n");
    return (TRUE);
  }

  if (job[0].mode == JOB_LOCAL) {
    if (!KillLocalJob (job)) {
      job[0].state = JOB_HUNG;
      if (VerboseMode()) gprint (GP_LOG, "child process %d is hung, cannot kill\n", job[0].pid);
      return (FALSE);
    }
  } else {
    if (!KillControllerJob (job)) {
      job[0].state = JOB_HUNG;
      if (VerboseMode()) gprint (GP_LOG, "child process %d is hung, cannot kill\n", job[0].pid);
      return (FALSE);
    }
  }    
  DeleteJob (job);
  gprint (GP_LOG, "job removed\n");
  return (TRUE);
}
