Use waitpid for child having groupid 1
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I searched a lot but didn't find solution. So it can be silly question.
The format of waitpid is
pid_t waitpid (pid_t pid, int *status, int options)
The pid parameter specifies exactly which process or processes to wait for. Its values fall into
four camps:
< -1
Wait for any child process whose process group ID is equal to the absolute value of this value.
-1
Wait for any child process. This is the same behavior as wait( ).
0
Wait for any child process that belongs to the same process group as the calling process.
> 0
Wait for any child process whose pid is exactly the value provided.
Now the question is what if parent and child have different group id and group id of child is 1. How to use waitpid for this specific child? Because we can't use -1 it will tell to wait for any child.
process system-calls process-groups wait
add a comment |Â
up vote
0
down vote
favorite
I searched a lot but didn't find solution. So it can be silly question.
The format of waitpid is
pid_t waitpid (pid_t pid, int *status, int options)
The pid parameter specifies exactly which process or processes to wait for. Its values fall into
four camps:
< -1
Wait for any child process whose process group ID is equal to the absolute value of this value.
-1
Wait for any child process. This is the same behavior as wait( ).
0
Wait for any child process that belongs to the same process group as the calling process.
> 0
Wait for any child process whose pid is exactly the value provided.
Now the question is what if parent and child have different group id and group id of child is 1. How to use waitpid for this specific child? Because we can't use -1 it will tell to wait for any child.
process system-calls process-groups wait
Mmm, not interested in an answer? I explained you how to do what you like usingwaitid()
.
â schily
Jul 4 at 14:41
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I searched a lot but didn't find solution. So it can be silly question.
The format of waitpid is
pid_t waitpid (pid_t pid, int *status, int options)
The pid parameter specifies exactly which process or processes to wait for. Its values fall into
four camps:
< -1
Wait for any child process whose process group ID is equal to the absolute value of this value.
-1
Wait for any child process. This is the same behavior as wait( ).
0
Wait for any child process that belongs to the same process group as the calling process.
> 0
Wait for any child process whose pid is exactly the value provided.
Now the question is what if parent and child have different group id and group id of child is 1. How to use waitpid for this specific child? Because we can't use -1 it will tell to wait for any child.
process system-calls process-groups wait
I searched a lot but didn't find solution. So it can be silly question.
The format of waitpid is
pid_t waitpid (pid_t pid, int *status, int options)
The pid parameter specifies exactly which process or processes to wait for. Its values fall into
four camps:
< -1
Wait for any child process whose process group ID is equal to the absolute value of this value.
-1
Wait for any child process. This is the same behavior as wait( ).
0
Wait for any child process that belongs to the same process group as the calling process.
> 0
Wait for any child process whose pid is exactly the value provided.
Now the question is what if parent and child have different group id and group id of child is 1. How to use waitpid for this specific child? Because we can't use -1 it will tell to wait for any child.
process system-calls process-groups wait
edited Jul 4 at 13:19
asked Jul 4 at 13:06
Debian_yadav
8322522
8322522
Mmm, not interested in an answer? I explained you how to do what you like usingwaitid()
.
â schily
Jul 4 at 14:41
add a comment |Â
Mmm, not interested in an answer? I explained you how to do what you like usingwaitid()
.
â schily
Jul 4 at 14:41
Mmm, not interested in an answer? I explained you how to do what you like using
waitid()
.â schily
Jul 4 at 14:41
Mmm, not interested in an answer? I explained you how to do what you like using
waitid()
.â schily
Jul 4 at 14:41
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You can only wait for children from your process.
If the child changes it's process group id, the new process group id can be used as a negative number with waitpid()
.
BTW: the function waitpid()
is deprecated since 1989. The modern function is: waitid()
and it supports what you like:
waitid(idtype, id, infop, opts)
idtype_t idtype;
id_t id;
siginfo_t *infop; /* Must be != NULL */
int opts;
If you like to wait for a process group, use:
waitid(P_PGID, pgid, infop, opts);
So if you really have a process under process group ID 1, call:
waitid(P_PGID, 1, infop, opts);
But since init
already uses this process group id, you would need to be the init
process in order to able to have children under pgid 1.
This however will not work, if you are on a platform that does not implement waitid()
as a syscall but as an emulation on top of the outdated waitpid()
.
The advantages of waitid()
are:
allows to cleanly specify what to wait for (e.g. P_PID P_PGID P_ALL)
returns all 32 bits from the
exit(2)
parameter in the child back to the parent process.allows to wait with the flag:
WNOWAIT
that does not reap the child and keeps it for later in the process table.
BTW: The siginfo_t pointer in waitid()
is identical to the second parameter of the signal handler function for SIGCHLD
.
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
add a comment |Â
up vote
0
down vote
You'll have some trouble getting into a situation where the process group ID of a child process is 1
.
Process groups are mostly for shells running foreground and background processes (pipelines). Usually, when a new process group is started, it gets the process group id from the first process's process id. You won't get a child with PID 1, so you won't get a child with PGID 1, either.
The setpgid()
call allows to move process from one process group to another, but they still need to be part of the same (login) session, so you can't move a process to PGID 1 that way either.
If you have a shell running as PID 1, then it could have PGID 1, too. But as long as the shell changes the PGID of its children, they'll have a different PGID.
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID towaitpid()
. Neither did I see you answer that question, btw. Your answer useswaitid()
, notwaitpid()
, which, as you say, is different.
â ilkkachu
Jul 4 at 16:50
So you did not read my answer.waitpid()
is outdated since 29 years and it's successorwaitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.
â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You can only wait for children from your process.
If the child changes it's process group id, the new process group id can be used as a negative number with waitpid()
.
BTW: the function waitpid()
is deprecated since 1989. The modern function is: waitid()
and it supports what you like:
waitid(idtype, id, infop, opts)
idtype_t idtype;
id_t id;
siginfo_t *infop; /* Must be != NULL */
int opts;
If you like to wait for a process group, use:
waitid(P_PGID, pgid, infop, opts);
So if you really have a process under process group ID 1, call:
waitid(P_PGID, 1, infop, opts);
But since init
already uses this process group id, you would need to be the init
process in order to able to have children under pgid 1.
This however will not work, if you are on a platform that does not implement waitid()
as a syscall but as an emulation on top of the outdated waitpid()
.
The advantages of waitid()
are:
allows to cleanly specify what to wait for (e.g. P_PID P_PGID P_ALL)
returns all 32 bits from the
exit(2)
parameter in the child back to the parent process.allows to wait with the flag:
WNOWAIT
that does not reap the child and keeps it for later in the process table.
BTW: The siginfo_t pointer in waitid()
is identical to the second parameter of the signal handler function for SIGCHLD
.
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
add a comment |Â
up vote
0
down vote
accepted
You can only wait for children from your process.
If the child changes it's process group id, the new process group id can be used as a negative number with waitpid()
.
BTW: the function waitpid()
is deprecated since 1989. The modern function is: waitid()
and it supports what you like:
waitid(idtype, id, infop, opts)
idtype_t idtype;
id_t id;
siginfo_t *infop; /* Must be != NULL */
int opts;
If you like to wait for a process group, use:
waitid(P_PGID, pgid, infop, opts);
So if you really have a process under process group ID 1, call:
waitid(P_PGID, 1, infop, opts);
But since init
already uses this process group id, you would need to be the init
process in order to able to have children under pgid 1.
This however will not work, if you are on a platform that does not implement waitid()
as a syscall but as an emulation on top of the outdated waitpid()
.
The advantages of waitid()
are:
allows to cleanly specify what to wait for (e.g. P_PID P_PGID P_ALL)
returns all 32 bits from the
exit(2)
parameter in the child back to the parent process.allows to wait with the flag:
WNOWAIT
that does not reap the child and keeps it for later in the process table.
BTW: The siginfo_t pointer in waitid()
is identical to the second parameter of the signal handler function for SIGCHLD
.
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You can only wait for children from your process.
If the child changes it's process group id, the new process group id can be used as a negative number with waitpid()
.
BTW: the function waitpid()
is deprecated since 1989. The modern function is: waitid()
and it supports what you like:
waitid(idtype, id, infop, opts)
idtype_t idtype;
id_t id;
siginfo_t *infop; /* Must be != NULL */
int opts;
If you like to wait for a process group, use:
waitid(P_PGID, pgid, infop, opts);
So if you really have a process under process group ID 1, call:
waitid(P_PGID, 1, infop, opts);
But since init
already uses this process group id, you would need to be the init
process in order to able to have children under pgid 1.
This however will not work, if you are on a platform that does not implement waitid()
as a syscall but as an emulation on top of the outdated waitpid()
.
The advantages of waitid()
are:
allows to cleanly specify what to wait for (e.g. P_PID P_PGID P_ALL)
returns all 32 bits from the
exit(2)
parameter in the child back to the parent process.allows to wait with the flag:
WNOWAIT
that does not reap the child and keeps it for later in the process table.
BTW: The siginfo_t pointer in waitid()
is identical to the second parameter of the signal handler function for SIGCHLD
.
You can only wait for children from your process.
If the child changes it's process group id, the new process group id can be used as a negative number with waitpid()
.
BTW: the function waitpid()
is deprecated since 1989. The modern function is: waitid()
and it supports what you like:
waitid(idtype, id, infop, opts)
idtype_t idtype;
id_t id;
siginfo_t *infop; /* Must be != NULL */
int opts;
If you like to wait for a process group, use:
waitid(P_PGID, pgid, infop, opts);
So if you really have a process under process group ID 1, call:
waitid(P_PGID, 1, infop, opts);
But since init
already uses this process group id, you would need to be the init
process in order to able to have children under pgid 1.
This however will not work, if you are on a platform that does not implement waitid()
as a syscall but as an emulation on top of the outdated waitpid()
.
The advantages of waitid()
are:
allows to cleanly specify what to wait for (e.g. P_PID P_PGID P_ALL)
returns all 32 bits from the
exit(2)
parameter in the child back to the parent process.allows to wait with the flag:
WNOWAIT
that does not reap the child and keeps it for later in the process table.
BTW: The siginfo_t pointer in waitid()
is identical to the second parameter of the signal handler function for SIGCHLD
.
edited Jul 4 at 15:25
answered Jul 4 at 13:16
schily
8,53921435
8,53921435
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
add a comment |Â
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
The main doubt was how to pass child group id as -1 because by this the sense will change.
â Debian_yadav
Jul 4 at 15:25
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
Well, I explained how to wait for process group 1 without waiting for all processes. Wasn't this what you were asking for?
â schily
Jul 4 at 15:27
add a comment |Â
up vote
0
down vote
You'll have some trouble getting into a situation where the process group ID of a child process is 1
.
Process groups are mostly for shells running foreground and background processes (pipelines). Usually, when a new process group is started, it gets the process group id from the first process's process id. You won't get a child with PID 1, so you won't get a child with PGID 1, either.
The setpgid()
call allows to move process from one process group to another, but they still need to be part of the same (login) session, so you can't move a process to PGID 1 that way either.
If you have a shell running as PID 1, then it could have PGID 1, too. But as long as the shell changes the PGID of its children, they'll have a different PGID.
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID towaitpid()
. Neither did I see you answer that question, btw. Your answer useswaitid()
, notwaitpid()
, which, as you say, is different.
â ilkkachu
Jul 4 at 16:50
So you did not read my answer.waitpid()
is outdated since 29 years and it's successorwaitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.
â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
add a comment |Â
up vote
0
down vote
You'll have some trouble getting into a situation where the process group ID of a child process is 1
.
Process groups are mostly for shells running foreground and background processes (pipelines). Usually, when a new process group is started, it gets the process group id from the first process's process id. You won't get a child with PID 1, so you won't get a child with PGID 1, either.
The setpgid()
call allows to move process from one process group to another, but they still need to be part of the same (login) session, so you can't move a process to PGID 1 that way either.
If you have a shell running as PID 1, then it could have PGID 1, too. But as long as the shell changes the PGID of its children, they'll have a different PGID.
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID towaitpid()
. Neither did I see you answer that question, btw. Your answer useswaitid()
, notwaitpid()
, which, as you say, is different.
â ilkkachu
Jul 4 at 16:50
So you did not read my answer.waitpid()
is outdated since 29 years and it's successorwaitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.
â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You'll have some trouble getting into a situation where the process group ID of a child process is 1
.
Process groups are mostly for shells running foreground and background processes (pipelines). Usually, when a new process group is started, it gets the process group id from the first process's process id. You won't get a child with PID 1, so you won't get a child with PGID 1, either.
The setpgid()
call allows to move process from one process group to another, but they still need to be part of the same (login) session, so you can't move a process to PGID 1 that way either.
If you have a shell running as PID 1, then it could have PGID 1, too. But as long as the shell changes the PGID of its children, they'll have a different PGID.
You'll have some trouble getting into a situation where the process group ID of a child process is 1
.
Process groups are mostly for shells running foreground and background processes (pipelines). Usually, when a new process group is started, it gets the process group id from the first process's process id. You won't get a child with PID 1, so you won't get a child with PGID 1, either.
The setpgid()
call allows to move process from one process group to another, but they still need to be part of the same (login) session, so you can't move a process to PGID 1 that way either.
If you have a shell running as PID 1, then it could have PGID 1, too. But as long as the shell changes the PGID of its children, they'll have a different PGID.
answered Jul 4 at 13:19
ilkkachu
47.3k668130
47.3k668130
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID towaitpid()
. Neither did I see you answer that question, btw. Your answer useswaitid()
, notwaitpid()
, which, as you say, is different.
â ilkkachu
Jul 4 at 16:50
So you did not read my answer.waitpid()
is outdated since 29 years and it's successorwaitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.
â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
add a comment |Â
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID towaitpid()
. Neither did I see you answer that question, btw. Your answer useswaitid()
, notwaitpid()
, which, as you say, is different.
â ilkkachu
Jul 4 at 16:50
So you did not read my answer.waitpid()
is outdated since 29 years and it's successorwaitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.
â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
The question was how to wait for process group 1 and you did not answer that question.
â schily
Jul 4 at 15:40
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID to
waitpid()
. Neither did I see you answer that question, btw. Your answer uses waitid()
, not waitpid()
, which, as you say, is different.â ilkkachu
Jul 4 at 16:50
@schily, strictly speaking, the question was "How to use waitpid for this specific child?". I didn't answer that, since with very high likelihood the situation won't come up. The answer to that would have been to pass the child's PID to
waitpid()
. Neither did I see you answer that question, btw. Your answer uses waitid()
, not waitpid()
, which, as you say, is different.â ilkkachu
Jul 4 at 16:50
So you did not read my answer.
waitpid()
is outdated since 29 years and it's successor waitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.â schily
Jul 4 at 17:57
So you did not read my answer.
waitpid()
is outdated since 29 years and it's successor waitid()
can do it. So I did answer the question on how to wait for pgrp 1. The questioner did not mention that he is working in a computer museum with machines from the 1980s where the OS has never been updated.â schily
Jul 4 at 17:57
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
@schily, I read your answer. Regardless of if the function they asked for is old or has a better replacement, that's the function they asked about. They didn't ask about waiting for the child using any system call. You didn't give an answer using that particular function, and for a reason. I, also, didn't give an answer using that particular function, but for another reason. But if you start nitpicking about what the question actually asks, please at least nitpick correctly.
â ilkkachu
Jul 4 at 18:34
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453426%2fuse-waitpid-for-child-having-groupid-1%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Mmm, not interested in an answer? I explained you how to do what you like using
waitid()
.â schily
Jul 4 at 14:41