pid/gid mess improved

Not sure if dependencies are correct. please check.
where is there the comment starting here?