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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:45:17+00:00 2026-05-25T23:45:17+00:00

for example, i want to get an array of 4 ints from child to

  • 0

for example, i want to get an array of 4 ints from child to parent. parent calls

read(apipe, buf, sizeof(int)*4);

child calls

for(int i=0; i<4;i++)
    write(bpipe, &array[i], sizeof(int));

does this do what I intend (getting 4 ints to the parent) or does the parent simply get the first integer?

I tried searching for this answer elsewhere, but either I don’t know how to search or this is too subtle (or on the other hand too seemingly obvious) for literature to dwell on it much.

EDIT: To clarify further, I was trying to write a 4-part message and read all 4 parts in one read(). See comments on accepted answer.

  • 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-05-25T23:45:18+00:00Added an answer on May 25, 2026 at 11:45 pm

    read and write work with bytes, not messages. For details of how they behave with pipes, see the documentation in POSIX:

    • http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
    • http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html

    In your code, I think the read should always get 4 ints, due to:

    Upon successful completion, where nbyte is greater than 0, read() shall mark for update the last data access timestamp of the file, and shall return the number of bytes read. This number shall never be greater than nbyte. The value returned may be less than nbyte if the number of bytes left in the file is less than nbyte, if the read() request was interrupted by a signal, or if the file is a pipe or FIFO or special file and has fewer than nbyte bytes immediately available for reading. For example, a read() from a file associated with a terminal may return one typed line of data.

    There will always be 4 ints available for reading, because 4*sizeof(int) < PIPE_BUF and thus writes of this size are atomic.

    It’s possible that the allowance for read to return a short read when interrupted by a signal could come into play, but that should not be able to happen (in the real world, at least) when sufficiently many bytes are available immediately.

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

Sidebar

Related Questions

I want to get values from an array, For example this is array: $tags_array
I want to get the single digits from two digits.for example if 36 I
I have an array from ten (or more) numbers, for example: arr[1,2,3,4,5,6,7,8,9,10] I want
I want to write a named scope to get a record from its id.
I have a URL of form http://www.example.com?foo=one&foo=two I want to get an array of
From a dataframe I get a new array, sliced from a dataframe. I want
I want to write a method that when supplied an array of ints will
I want to get N random numbers whose sum is a value. For example,
If I want to get a user that has the email address of 'me@example.com',
I only want a simple Splash Screen Example. Get the Code, Insert my picture,

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.