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

  • Home
  • SEARCH
  • 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 8282623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:26:11+00:00 2026-06-08T10:26:11+00:00

I want to write some C code that has the following requirement: Repeated fork

  • 0

I want to write some C code that has the following requirement:

  1. Repeated fork exec.
  2. The fork’ed process should use a large amount of memory and then either give it up or just die or I would just kill it.

Any ideas?

  • 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-08T10:26:12+00:00Added an answer on June 8, 2026 at 10:26 am
    int main (int argc, char *argv[]) {
        unsigned long long bytes;
        char bytes_str[32];
        void *buf;
        int i;
        if (argc < 2) {
            fprintf(stderr, "usage: %s [megabytes]\n", argv[0]);
            exit(EXIT_SUCCESS);
        } else if (argc < 3) {
            switch (fork()) {
            case 0:  break;
            case -1: perror("fork");
                     exit(EXIT_FAILURE);
            default: exit(EXIT_SUCCESS);
            }
            bytes = strtoull(argv[1], 0, 0) * 1024 * 1024;
            snprintf(bytes_str, sizeof(bytes_str), "%llu", bytes);
            if (execlp(argv[0], argv[0], "child", bytes_str, (char *)0) != 0) {
                perror("execlp");
                exit(EXIT_FAILURE);
            }
            /* NOT REACHED */
        } else {
            bytes = strtoull(argv[2], 0, 0);
        }
        if (bytes < 1024*1024) exit(EXIT_SUCCESS);
        buf = malloc(bytes);
        if (buf == 0) {
            perror("malloc");
            exit(EXIT_FAILURE);
        }
        memset(buf, '\xff', bytes);
        free(buf);
        bytes /= 2;
        snprintf(bytes_str, sizeof(bytes_str), "%llu", bytes);
        for (i = 0; i < 2; ++i) {
            switch (fork()) {
            case 0:  break;
            case -1: perror("fork");
                     exit(EXIT_FAILURE);
            default: continue;
            }
            if (execlp(argv[0], argv[0], "child", bytes_str, (char *)0) != 0) {
                perror("execlp");
                exit(EXIT_FAILURE);
            }
            /* NOT REACHED */
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a java code that executes some Linux command: String cmd
I have some code that has to compile for multiple platforms. The following will
i just join phonegap, i want a built test application. i write some code
I want to write some plugin to analysis Java source code. Which part of
I want a piece of Javascript code or some guidance on how to write
I want to write some configuration in web.config file, that will make my ASP.Net
I want to write in a bash script a piece of code that checks
I'm trying to write some code that deletes an image off the hard-disk once
Some background: I have an database that I want to use linq-to-sql to update
I want to reuse some code I wrote to add some functionality to a

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.