def watchRunProgram(self, pid):
        usingMem = 0

        while True:
            wpid, status, res = os.wait4(pid, 0)
            signal.signal(signal.SIGXCPU, self.sigHandler)

            # 정상 종료된 경우
            if os.WIFEXITED(status):
                return 'Grading', res[0], usingMem

            exitCode = os.WEXITSTATUS(status)

            # 종료 코드에 따라 return
            if exitCode is 24:
                return ENUMResources.const.TIME_OVER, res[0], usingMem

            elif exitCode is not 5 and exitCode is not 0 and exitCode is not 17:
                return ENUMResources.const.RUNTIME_ERROR, 0, 0

            elif os.WIFSIGNALED(status):
                try:
                    ptrace.kill(pid)
                except Exception as e:
                    pass

                return ENUMResources.const.RUNTIME_ERROR, 0, 0

            # 메모리 사용량 측정
            else:
                usingMem = self.getUsingMemory(pid, usingMem, res[6])

                ptrace.syscall(pid, 0)
 def watchRunProgram(self, pid):
     usingMem = 0
     
     while True:
         wpid, status, res = os.wait4(pid,0)
         signal.signal(signal.SIGXCPU, self.sigHandler)
         
         # 정상 종료된 경우
         if os.WIFEXITED(status):
             return 'Grading', res[0], usingMem
         
         exitCode = os.WEXITSTATUS(status)
         
         # 종료 코드에 따라 return
         if  exitCode is 24:
             return ENUMResources.const.TIME_OVER, res[0], usingMem
         
         elif exitCode is not 5 and exitCode is not 0 and exitCode is not 17:
             return ENUMResources.const.RUNTIME_ERROR, 0, 0 
         
         elif os.WIFSIGNALED(status):
             try:
                 ptrace.kill(pid)
             except Exception as e:
                 pass
             
             return ENUMResources.const.RUNTIME_ERROR, 0, 0
         
         # 메모리 사용량 측정
         else:
             usingMem = self.getUsingMemory(pid, usingMem, res[6])
             
             ptrace.syscall(pid, 0)
示例#3
0
    def __traceProgram(self, pid):
        while True:
            wpid, status, res = os.wait4(pid, 0)

            # normal termination
            if os.WIFEXITED(status):
                return True, res[0]

            # abnormal termination
            elif os.WIFSIGNALED(status):
                try:
                    ptrace.kill(pid)
                except Exception as e:
                    pass

                return RUNTIME_ERROR, res[0]

            else:
                ptrace.syscall(pid, 0)
 def WatchRunProgram(self, pid):
     usingMem = 0
     
     while True:
         wpid, status, res = os.wait4(pid,0)
 
         if os.WIFEXITED(status):
             return True, res[0], usingMem
         
         exitCode = os.WEXITSTATUS(status)
         if exitCode != 5 and exitCode != 0 and exitCode != 17:
             ptrace.kill(pid)
             return ENUMResources.const.RUNTIME_ERROR, 0, 0 
             
         elif os.WIFSIGNALED(status):
             ptrace.kill(pid)
             return ENUMResources.const.TIME_OVER, res[0], usingMem
         
         else:
             usingMem = self.GetUsingMemory(pid, usingMem)
             
             
             ptrace.syscall(pid, 0)
示例#5
0
    global _skipcallafter
    _skipcallafter[pid] = 1


def hard_kill(pid):
    # FIX: isn't this a race?  don't we need to wait on the child?
    try:
        poke_args(pid, 6, [0, 0, 0, 0, 0, 0])
    except OSError, e:
        print "warning: attempt to annul last syscall by zapping args failed" " (pid=%s, error=%s)" % (pid, e)
    try:
        ptrace.pokeuser(pid, ORIG_EAX, _badcall)
    except OSError, e:
        print "warning: attempt to annul last syscall" " (pid=%s, error=%s)" % (pid, e)
    try:
        ptrace.kill(pid)
    except OSError, e:
        print "warning: attempt to ptrace.kill process failed" " (pid=%s, error=%s)" % (pid, e)
    except:
        # XXX: should we really catch this?  we shouldn't be absorbing
        # arbitrary exceptions; this will cause trouble
        print "warning: attempt to ptrace.kill process failed strangely" " (pid=%s, error=%s)" % (pid, e)
        raise

    try:
        # SIGKILL isn't delivered until completion of the current syscall; this
        # function tries to abort the current syscall before killing the child.
        os.kill(pid, signal.SIGKILL)
    except OSError, e:
        print "warning: attempt to os.kill process failed" " (pid=%s, error=%s)" % (pid, e)
    except:
示例#6
0

def hard_kill(pid):
    # FIX: isn't this a race?  don't we need to wait on the child?
    try:
        poke_args(pid, 6, [0, 0, 0, 0, 0, 0])
    except OSError, e:
        print "warning: attempt to annul last syscall by zapping args failed" \
                     " (pid=%s, error=%s)" % (pid, e)
    try:
        ptrace.pokeuser(pid, ORIG_EAX, _badcall)
    except OSError, e:
        print "warning: attempt to annul last syscall" \
                     " (pid=%s, error=%s)" % (pid, e)
    try:
        ptrace.kill(pid)
    except OSError, e:
        print "warning: attempt to ptrace.kill process failed" \
                     " (pid=%s, error=%s)" % (pid, e)
    except:
        # XXX: should we really catch this?  we shouldn't be absorbing
        # arbitrary exceptions; this will cause trouble
        print "warning: attempt to ptrace.kill process failed strangely" \
                     " (pid=%s, error=%s)" % (pid, e)
        raise

    try:
        # SIGKILL isn't delivered until completion of the current syscall; this
        # function tries to abort the current syscall before killing the child.
        os.kill(pid, signal.SIGKILL)
    except OSError, e: