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 183947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:12:21+00:00 2026-05-11T15:12:21+00:00

I have this problem to solve that I have no idea how to do

  • 0

I have this problem to solve that I have no idea how to do it because there’s only a few system calls we can use to solve it and I don’t see how they are helpful for the situation.

The Exercise:
I have matrix with size [10][1000000] with integers and for each line I create a new process with fork(). The idea of each process is to go through all the numbers for that specific line and find a specific number then print a message about it. This was the first step of the problem and it’s done. The second step is to print the total of occurrences of that number on each line by order. And in the end, the grand total of occurrences of that number.

The Calls:
The system calls I can use are described like this in the document for this exercise:

  • pid_t fork(void);
  • void exit(int status);
  • pid_t wait(int *status);
  • pid_t waitpid(pid_t pid, int *status, int options);

The Problem:
I have no idea how to do it because the exit() call only allows me to pass a number below 256, what if the number of occurrences is larger than this number? How shall I return such a number?

Another Problem:
I don’t exactly understand the difference between wait() and waitpid() and how/where to use one over the other. Besides the man pages, are there any more documentation where I can see code examples and such to understand them better? Or can someone explain me the differences and provide a basic example demonstrating such differences?

  • 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. 2026-05-11T15:12:21+00:00Added an answer on May 11, 2026 at 3:12 pm

    Use waitpid() to garner the exit statuses of the child processes in sequence; using wait() makes no guarantee about the sequence in which the child corpses will be retrieved.

    On Unix, the exit status is limited to 8 bits, which can be treated as signed or unsigned by the program retrieving the data. You also get an 8 bit value identifying the signal number and core dump status of the terminated child. AFAIK, either the status or the signal bits are always zero (and often both – when the process exits successfully).

    If you don’t know that the numbers to be returned are smaller than 256, then exit status is not the way to go. As others have said, you have to use some other IPC in that case. If the only system calls permitted are those, then you have to conclude that the values will be less than 255, or that overflows don’t matter. Neither is satisfactory as a conclusion outside a homework exercise, but in the ‘real world’, you are not limited to just 4 system calls either.

    See also Exit codes bigger than 255?. Note that on Windows, the range of exit codes is much larger – but you don’t use the system calls listed in the question.


    Observation: when I do exit(1), the value in status from wait() is 256; is there a reason for that?

    Answer: yes. The low 8 bits of the status word encode the signal number and so on; the high 8 bits of the (16-bit) status word encode the exit status.

    See <sys/wait.h> and macros WIFEXITED(), WEXITSTATUS(), etc.

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

Sidebar

Ask A Question

Stats

  • Questions 240k
  • Answers 240k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One approch is to replace the parenthetical groups from the… May 13, 2026 at 7:16 am
  • Editorial Team
    Editorial Team added an answer I develop on Windows 7 machine for Windows 2008 because… May 13, 2026 at 7:16 am
  • Editorial Team
    Editorial Team added an answer Here's an approach, using mutable state: int lastPrime = 0;… May 13, 2026 at 7:16 am

Related Questions

I have this learning code I wrote for the morris seq in f# that
I am developing publishing site. I have some layouts that are pre-populated with web
I use the following MSDN code on my master page to detect if the
I have a hibernate object that gets detached and transferred to a thick java

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.