def runProgram(self, runCommandList):
        # 프로세스 우선순위 증가
        os.nice(19)

        # 프로그램 실행 결과 출력되는 stdout을 파일로 리다이렉션
        redirectionSTDOUT = os.open(
            FileNameNPathResources.const.OutputResultFileName,
            os.O_RDWR | os.O_CREAT)
        os.dup2(redirectionSTDOUT, 1)

        # 프로세스 사용 자원 제한
        soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
        rlimTime = int(self.limitTime / 1000) + 1

        resource.setrlimit(resource.RLIMIT_CPU, (rlimTime, hard))

        # 파이썬 런타임 에러 메시지 리다이렉션
        if self.usingLang == ListResources.const.Lang_PYTHON:
            redirectionSTDERROR = os.open('run.err', os.O_RDWR | os.O_CREAT)
            os.dup2(redirectionSTDERROR, 2)

        if self.caseCount is not 0:
            redirectionSTDIN = os.open('input.txt', os.O_RDONLY)
            os.dup2(redirectionSTDIN, 0)

        # 프로세스 추적/실행
        ptrace.traceme()

        os.execl(runCommandList[0], runCommandList[1], runCommandList[2])
 def runProgram(self, runCommandList):
     # 프로세스 우선순위 증가
     os.nice(19)
     
     # 프로그램 실행 결과 출력되는 stdout을 파일로 리다이렉션
     redirectionSTDOUT = os.open(FileNameNPathResources.const.OutputResultFileName,
                                 os.O_RDWR|os.O_CREAT)
     os.dup2(redirectionSTDOUT,1)
     
     # 프로세스 사용 자원 제한
     soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
     rlimTime = int(self.limitTime / 1000) + 1
     
     resource.setrlimit(resource.RLIMIT_CPU, (rlimTime,hard))
     
     # 파이썬 런타임 에러 메시지 리다이렉션
     if self.usingLang == ListResources.const.Lang_PYTHON:
         redirectionSTDERROR = os.open('run.err', os.O_RDWR|os.O_CREAT)
         os.dup2(redirectionSTDERROR, 2)
     
     if self.caseCount is not 0:
         redirectionSTDIN = os.open('input.txt', os.O_RDONLY)
         os.dup2(redirectionSTDIN, 0)
     
     # 프로세스 추적/실행
     ptrace.traceme()
         
     os.execl(runCommandList[0], runCommandList[1], runCommandList[2])
 def RunProgram(self, runCommandList):
     os.nice(19)
     
     reditectionSTDOUT = os.open('output.txt', os.O_RDWR|os.O_CREAT)
     os.dup2(reditectionSTDOUT,1)
     
     rlimTime = int(self.limitTime / 1000) + 1
     
     resource.setrlimit(resource.RLIMIT_CORE, (1024,1024))
     resource.setrlimit(resource.RLIMIT_CPU, (rlimTime,rlimTime))
     
     ptrace.traceme()
     
     if self.usingLang == ListResources.const.Lang_PYTHON or self.usingLang == ListResources.const.Lang_JAVA:
         reditectionSTDERROR = os.open('core.1', os.O_RDWR|os.O_CREAT)
         os.dup2(reditectionSTDERROR,2)
         
         os.execl(runCommandList[0], runCommandList[1], runCommandList[2])
         
     else:
         os.execl(runCommandList[0], runCommandList[1])
Пример #4
0
def do_main(allflags):
    global waitchannelhack, waitchannelstop

    sys.stdout = sys.stderr             # doesn't affect kids

    command, tricklist_obj = process_arguments(sys.argv)

    if not command:
        print 'error: no COMMAND given\n'
        usage()
        sys.exit(1)

    pid = os.fork()
    if (pid == 0):
        # XXX: is the child carrying any other odd signal handlers or
        # environment from the parent python interpreter?
        signal.signal(signal.SIGPIPE, signal.SIG_DFL) # python did SIG_IGN

        try:
            ptrace.traceme()
        except OSError, e:
            sys.exit('error: could not trace child, maybe already traced?'
                     ' (%s)' % e)

        # Python leaves a fd open to its initial script, which we close here.
        fddir = '/proc/self/fd/'
        fds = filter(lambda n: n > 2, map(int, os.listdir('/proc/self/fd/')))
        for fd in fds:
            try:
                if os.readlink('%s%s' % (fddir, fd)) == sys.argv[0]:
                    if debug():
                        print 'closing', fd
                    os.close(fd)
            except OSError, e:
                # one fd is used to listdir and it will be gone before readlink
                pass
Пример #5
0
def do_main(allflags):
    global waitchannelhack, waitchannelstop

    sys.stdout = sys.stderr  # doesn't affect kids

    command, tricklist_obj = process_arguments(sys.argv)

    if not command:
        print 'error: no COMMAND given\n'
        usage()
        sys.exit(1)

    pid = os.fork()
    if (pid == 0):
        # XXX: is the child carrying any other odd signal handlers or
        # environment from the parent python interpreter?
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)  # python did SIG_IGN

        try:
            ptrace.traceme()
        except OSError, e:
            sys.exit('error: could not trace child, maybe already traced?'
                     ' (%s)' % e)

        # Python leaves a fd open to its initial script, which we close here.
        fddir = '/proc/self/fd/'
        fds = filter(lambda n: n > 2, map(int, os.listdir('/proc/self/fd/')))
        for fd in fds:
            try:
                if os.readlink('%s%s' % (fddir, fd)) == sys.argv[0]:
                    if debug():
                        print 'closing', fd
                    os.close(fd)
            except OSError, e:
                # one fd is used to listdir and it will be gone before readlink
                pass
Пример #6
0
    def __runProgram(self, command, pid, path):
        os.nice(19)  # program priority setting

        # redirect stdout to text file

        redirectionSTDOUT = os.open(os.path.join(path,
                                                 str(pid) + '.txt'),
                                    os.O_RDWR | os.O_CREAT)
        os.dup2(redirectionSTDOUT, 1)

        if '<' in command:
            redirectionSTDIN = os.open(os.path.join(path, 'input.txt'),
                                       os.O_RDONLY)
            os.dup2(redirectionSTDIN, 0)

        # cpu using time limit
        soft, hard = resource.getrlimit(resource.RLIMIT_CPU)
        resource.setrlimit(resource.RLIMIT_CPU,
                           ((self.limitTime / 1000) + 1, hard))

        ptrace.traceme()

        # program run
        os.execv(command[0], tuple(command[1:]))