Process ID problem

S

sdac

Hi, below is code for a child process, i am trying to give it a group
ID which is +10 on the group ID of the parent process (writing a
simple shell here)
Somehow both print statements show same group ID as if setpgid has no
effect...

if((pid_child2=fork())==0)
{
printf("***hello from c2\n");

printf(" ***c2 gpid used to be %d\n", getpgid(0));
int pgpid = getpgid(0);
setpgid(0,pgpid+10);
printf(" ***c2 gpid was set to %d\n", getpgid(0));
..
..
..
}


SCREEN OUTPUT --->

***hello from c2
***c2 gpid used to be 15946
***c2 gpid was set to 15946
-------------------------

UPDATE:
both setpgid calls are returning -1 and errno EPERM.
Could this be due to the adding of 10 to pgpid ? is that
allowed. The reason i am picking this pgid (x+1) is because i have
two children processos and want them both to have same group ID as
each other, but yet different from there parent.



Any ideas ? Thanks
 
W

Walter Roberson

Hi, below is code for a child process, i am trying to give it a group
ID which is +10 on the group ID of the parent process (writing a
simple shell here)

Processes and group ids are not part of the C language, and are
artifacts of the operating system you are using. For assistance
with your difficulty, you should consult a group that specializes
in your operating system. Perhaps comp.unix.programming .
 
K

Kenneth Brody

sdac wrote:
[...]
printf(" ***c2 gpid used to be %d\n", getpgid(0));
int pgpid = getpgid(0);
setpgid(0,pgpid+10);
printf(" ***c2 gpid was set to %d\n", getpgid(0)); [...]
SCREEN OUTPUT --->

***hello from c2
***c2 gpid used to be 15946
***c2 gpid was set to 15946

While most of the above is OT for clc, the fact that errno is
being set to EPERM is a major hint. Check the man pages on
setpgid() and see what could cause that error. If that doesn't
help, the you need to go to a group where this would be topical,
perhaps comp.unix.programming.

[Hint: many if the "set" calls like this do not allow arbitrary
values to be set. Consider, for example, "setuid(getuid()+1)".]

[...]

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top