// File: MUST-Quick-Fry[P]Process-Scheduler/monitor.cpp
// Function: Project::Monitor::Monitor(char**)
Monitor::Monitor(char *command[]):command(command)
{
    int process;
    int status;
    
    start = times(&t_start);
    process = fork();

    if(process < 0){
        status = -1;
    }
    else if(process == 0){ 
        //signal(SIGINT, SIG_DFL); //Default handle every child process
        execvp(command[0],command);
        throw invalid_argument("Fail to execute Child Process!\n");
    }
    else{
        int status;
        set_pid(process);
        signal(SIGTSTP, sig_handler);
        signal(SIGCONT, sig_handler);
        signal(SIGTERM, sig_handler);
        waitpid(process,&status,0);

	// quit loop if the child process has been terminated!
    }
    
     // calculate time
    end = times(&t_end);  
    set_timeElapsed(end-start);
    set_userTime(t_end.tms_cutime);
    set_systermTime(t_end.tms_cstime);
    
    // output 
    cout << endl;        
    cout << endl;
    print_time();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, (%rdi)
movl $0x0, 0x8(%rdi)
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rdi)
xorps %xmm0, %xmm0
movsd %xmm0, 0x68(%rdi)
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rdi)
addq $0x78, %rdi
movq %rdi, -0x38(%rbp)
callq 0x4160
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
callq 0x33f0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
callq 0x30a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x66bd
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
jmp 0x678b
cmpl $0x0, -0x14(%rbp)
jne 0x6738
movq -0x10(%rbp), %rsi
movq (%rsi), %rdi
callq 0x31f0
movl $0x10, %edi
callq 0x3120
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
leaq 0x129bd(%rip), %rsi     # 0x190a7
callq 0x3490
jmp 0x66f1
movq -0x40(%rbp), %rdi
movq 0x1c8e4(%rip), %rsi     # 0x22fe0
movq 0x1c8cd(%rip), %rdx     # 0x22fd0
callq 0x3430
jmp 0x681d
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x31c0
jmp 0x680b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x680b
movq -0x30(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x62b0
jmp 0x6746
leaq -0x47d(%rip), %rsi      # 0x62d0
movq %rsi, -0x48(%rbp)
movl $0x14, %edi
callq 0x32d0
movq -0x48(%rbp), %rsi
movl $0x12, %edi
callq 0x32d0
movq -0x48(%rbp), %rsi
movl $0xf, %edi
callq 0x32d0
movl -0x14(%rbp), %edi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x3210
jmp 0x6787
jmp 0x6789
jmp 0x678b
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
callq 0x33f0
movq -0x30(%rbp), %rdi
movq %rax, 0x18(%rdi)
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rsi
subq %rax, %rsi
callq 0x6410
jmp 0x67b2
movq -0x30(%rbp), %rdi
movq 0x50(%rdi), %rsi
callq 0x6440
jmp 0x67c1
movq -0x30(%rbp), %rdi
movq 0x58(%rdi), %rsi
callq 0x6470
jmp 0x67d0
movq 0x1c7e9(%rip), %rdi     # 0x22fc0
movq 0x1c7d2(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0x67e5
movq 0x1c7d4(%rip), %rdi     # 0x22fc0
movq 0x1c7bd(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0x67fa
movq -0x30(%rbp), %rdi
callq 0x64a0
jmp 0x6805
addq $0x50, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x4190
movq -0x20(%rbp), %rdi
callq 0x3450
nopl (%rax)