首先定义进程状态的枚举类型为ProcessState
typedef enum {
NEW,
READY,
RUNNING,
BLOCKED,
TERMINATED
} ProcessState;
而后据图中进程运行代码
int main() {
ProcessState process = NEW;
printf("Process created. State: NEW\n");
process = READY;
printf("Process state changed. State: READY\n");
process = RUNNING;
printf("Process state changed. State: RUNNING\n");
process = BLOCKED;
printf("Process state changed. State: BLOCKED\n");
process = TERMINATED;
printf("Process state changed. State: TERMINATED\n");
return 0;
}
具体代码
运行结果