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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:51:48+00:00 2026-06-11T14:51:48+00:00

Let’s say I have the following pipeline: $ generator_process | filter_process | storage_process Is

  • 0

Let’s say I have the following pipeline:

$ generator_process | filter_process | storage_process

Is it possible for filter_process to find out the pid of generator_process and storage_process? If so, how? If not, why?

More generally, how can a process find the pids of processes it communicates with over a pipe?

I’m looking for a portable (POSIX) way to do this, but if it requires some platform-specific trickery, a Linux solution is what I’m looking for. I guess an answer in C would give most detail but if it involves the shell, I’m looking for a bash solution.

Please assume that I can change filter_process but generator_process and storage_process are programs that I have no possibility or desire to alter (they could be standard Unix tools that I don’t want to fiddle with). Also, wrapping them in scripts that write their pids to disk is not the solution I’m after.

  • 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-11T14:51:49+00:00Added an answer on June 11, 2026 at 2:51 pm

    Note that one end of a pipe might be open in more than one process simultaneously (through fork() or sendmsg file-descriptor transmission), so you might not get just one answer.

    In Linux, you can examine /proc/<pid>/fd to see what fds it has open (you need to be root, or the same uid as the target process). I just ran grep a | grep b and got the following output:

    /proc/10442/fd:
    total 0
    dr-x------ 2 nneonneo nneonneo  0 Sep 20 02:19 .
    dr-xr-xr-x 7 nneonneo nneonneo  0 Sep 20 02:19 ..
    lrwx------ 1 nneonneo nneonneo 64 Sep 20 02:19 0 -> /dev/pts/5
    l-wx------ 1 nneonneo nneonneo 64 Sep 20 02:19 1 -> pipe:[100815116]
    lrwx------ 1 nneonneo nneonneo 64 Sep 20 02:19 2 -> /dev/pts/5
    
    /proc/10443/fd:
    total 0
    dr-x------ 2 nneonneo nneonneo  0 Sep 20 02:19 .
    dr-xr-xr-x 7 nneonneo nneonneo  0 Sep 20 02:19 ..
    lr-x------ 1 nneonneo nneonneo 64 Sep 20 02:19 0 -> pipe:[100815116]
    lrwx------ 1 nneonneo nneonneo 64 Sep 20 02:19 1 -> /dev/pts/5
    lrwx------ 1 nneonneo nneonneo 64 Sep 20 02:19 2 -> /dev/pts/5
    

    So it follows that by using readlink on your own process’s fd, followed by readlink on other process fds you own, you can figure out who is on the other side of the pipe.

    Madly hackish way to find out (from within a Bash script) which pids and fds are connected to a particular pipe:

    get_fd_target() {
        pid=$1
        fd=$2
        readlink /proc/$pid/fd/$fd
    }
    
    find_fd_target() {
        target=$1
        for i in /proc/*/fd/*; do
            if [ "`readlink $i`" == "$target" ]; then
                echo $i
            fi
        done
    }
    

    Then, if you want to find out what fds on the system are connected to your script’s stdin:

    find_fd_target `get_fd_target $$ 0`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have the following classes : public class MyProductCode { private String
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following two lists of tuples myList = [(1, 7),
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in

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.