2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _TASK_
|
|
|
|
#define _TASK_
|
|
|
|
|
2002-06-06 18:42:01 +00:00
|
|
|
#include "windows_cpp.h"
|
|
|
|
#ifdef _WIN32
|
2002-10-06 00:43:54 +00:00
|
|
|
#include <afxwin.h>
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <vector>
|
2002-06-21 06:52:47 +00:00
|
|
|
#include "client_types.h"
|
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
class CLIENT_STATE;
|
|
|
|
typedef int PROCESS_ID;
|
|
|
|
|
2002-12-05 19:13:06 +00:00
|
|
|
// Possible states of a process in an ACTIVE_TASK
|
|
|
|
#define PROCESS_UNINITIALIZED 0
|
|
|
|
#define PROCESS_RUNNING 1
|
|
|
|
#define PROCESS_EXITED 2
|
|
|
|
#define PROCESS_WAS_SIGNALED 3
|
|
|
|
#define PROCESS_EXIT_UNKNOWN 4
|
2002-12-06 07:33:45 +00:00
|
|
|
#define PROCESS_ABORT_PENDING 5
|
|
|
|
// process exceeded limits; killed it, waiting to exit
|
|
|
|
#define PROCESS_ABORTED 6
|
|
|
|
// process has exited
|
|
|
|
#define PROCESS_COULDNT_START 7
|
2002-12-05 19:13:06 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
// Represents a task in progress.
|
|
|
|
// The execution of a task may be divided into many "episodes"
|
|
|
|
// (if the host is turned off/on, e.g.)
|
|
|
|
// A task may checkpoint now and then.
|
|
|
|
// Each episode begins with the state of the last checkpoint.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
|
|
|
class ACTIVE_TASK {
|
|
|
|
public:
|
2002-06-06 18:42:01 +00:00
|
|
|
#ifdef _WIN32
|
2002-10-24 16:54:31 +00:00
|
|
|
HANDLE pid_handle,thread_handle;
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
RESULT* result;
|
|
|
|
WORKUNIT* wup;
|
|
|
|
APP_VERSION* app_version;
|
|
|
|
PROCESS_ID pid;
|
|
|
|
int slot; // which slot (determines directory)
|
|
|
|
int state;
|
|
|
|
int exit_status;
|
|
|
|
int signal;
|
2002-08-05 00:29:34 +00:00
|
|
|
double fraction_done;
|
2002-12-06 07:33:45 +00:00
|
|
|
// App's estimate of how much of the work unit is done.
|
|
|
|
// Passed from the application via an API call;
|
|
|
|
// will be zero if the app doesn't use this call
|
2002-08-05 00:29:34 +00:00
|
|
|
double starting_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// total CPU time at the start of current episode
|
2002-08-05 00:29:34 +00:00
|
|
|
double checkpoint_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// total CPU at the last checkpoint
|
2002-08-05 00:29:34 +00:00
|
|
|
double current_cpu_time;
|
2002-12-06 07:33:45 +00:00
|
|
|
// most recent total CPU time reported by app
|
|
|
|
int current_disk_usage(double&);
|
|
|
|
// disk used by output files and temp files of this task
|
2002-08-24 00:41:25 +00:00
|
|
|
char slot_dir[256]; // directory where process runs
|
2002-12-06 07:33:45 +00:00
|
|
|
double max_cpu_time;
|
|
|
|
double max_disk_usage;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
ACTIVE_TASK();
|
|
|
|
int init(RESULT*);
|
|
|
|
|
|
|
|
int start(bool first_time); // start the task running
|
2002-12-06 07:33:45 +00:00
|
|
|
int request_exit();
|
|
|
|
// ask a task to exit. doesn't wait for it to do so.
|
|
|
|
int request_pause();
|
|
|
|
// ask a task to pause. doesn't wait for it to do so.
|
|
|
|
int kill_task();
|
|
|
|
// externally kill the task. doesn't wait for exit
|
|
|
|
int abort();
|
|
|
|
// kill, and flag as abort pending
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-12-06 07:33:45 +00:00
|
|
|
int suspend();
|
|
|
|
int unsuspend();
|
2002-06-21 18:31:32 +00:00
|
|
|
|
2002-08-05 00:29:34 +00:00
|
|
|
bool check_app_status_files();
|
2002-11-20 20:14:48 +00:00
|
|
|
double est_time_to_completion();
|
2002-12-05 21:56:33 +00:00
|
|
|
bool read_stderr_file();
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
int write(FILE*);
|
|
|
|
int parse(FILE*, CLIENT_STATE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ACTIVE_TASK_SET {
|
|
|
|
public:
|
|
|
|
vector<ACTIVE_TASK*> active_tasks;
|
|
|
|
int insert(ACTIVE_TASK*);
|
|
|
|
int remove(ACTIVE_TASK*);
|
|
|
|
ACTIVE_TASK* lookup_pid(int);
|
|
|
|
bool poll();
|
2002-06-21 18:31:32 +00:00
|
|
|
bool poll_time();
|
2002-04-30 22:22:54 +00:00
|
|
|
void suspend_all();
|
|
|
|
void unsuspend_all();
|
|
|
|
int restart_tasks();
|
2002-07-01 18:16:31 +00:00
|
|
|
void exit_tasks();
|
2002-08-26 22:14:06 +00:00
|
|
|
int get_free_slot(int total_slots);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
int write(FILE*);
|
|
|
|
int parse(FILE*, CLIENT_STATE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|