Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the pid of cmd_a in a pipelined command group #9

Open
guorzhen opened this issue Oct 22, 2015 · 0 comments
Open

Getting the pid of cmd_a in a pipelined command group #9

guorzhen opened this issue Oct 22, 2015 · 0 comments

Comments

@guorzhen
Copy link

# Suppose this:
#
#   cmd_a | cmd_b &

Noticed the comment (and the code) about getting the pid of cmd_a, but the rest of the script doesn't seem to make use of it. Anyway, if you still need to get it (more elegantly), here are two other ways:

# Inside cmd_b
PID=$(ps -p $$ -o pgid=)

# or (tested only on cygwin)
PID=$(</proc/$$/pgid)

# Outside cmd_b
# same command with the above, but replace $$ with $!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant