Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:16:41+00:00 2026-06-15T21:16:41+00:00

Recently I have made a plan to develop a Online Judge system (like spoj

  • 0

Recently I have made a plan to develop a Online Judge system (like spoj). And I have write a judge script in python. It forks every time when it receives one submitted code, and then compile the code and use subprocess.Popen to start the program. But when I get program’s memory usage with resource.getrusage(resource.RUSAGE_CHILDREN), it returns memory of the forked python process instead of the subprocess.

Below is some of my code:

try:
    programThread = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, preexec_fn = self.limit, bufsize = -1)
except OSError:
    self.status.value = -2
    return -2
self.JudgeID.value = programThread.pid
programOutput = programThread.communicate(_in)
self.status.value = 0
Res = resource.getrusage(resource.RUSAGE_CHILDREN)
self.cpuusage.value = Res.ru_utime + Res.ru_stime
self.memoryusage.value = Res.ru_maxrss * resource.getpagesize()

cpuusage and memoryusage is shared memory created by multiprocessing.Value, the value of memoryusage is 12M. But via top, i’ve found, that the memory usage of forked python process is 12M while the subprocess is 900K. Are there anything wrong with my code? Sorry for my bad English.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:16:42+00:00Added an answer on June 15, 2026 at 9:16 pm

    This is called maxrss because it’s the maximum of the RSS usage of the child. The problem is that subprocess uses the standard way to create the subprocess: it first forks, creating a new process id (childpid), and then execv the intended subprocess’ executable (which doesn’t change the childpid). Then resource returns the maximum of the RSS among the lifetime of this childpid. If this child ran both a forked copy of Python at 12MB and another program at 900K, then the result is 12MB.

    I don’t really see how to fix this problem…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have recently made this script to rename files I scan for work
Alright so I have recently made the decision to put every string in my
I have made an application recently which has articles, etc, with a commenting/moderation system
I have recently made a change to an existing app and we would like
I have recently made some changes to my hosting account and a script I
I have recently made changes in some code that makes a char name field
I grew up on Java and have recently made a full switch to C#.
I have made Catifier.com recently, and once the user sets their own background image,
I have recently started reading about dependency injection and it has made me rethink
I recently made this simple navigation where you have a couple links that have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.