It is required to fork() and have the child call setsid() to ensure that the process calling setsid() isn't already a process group leader (setsid() wants to make the calling process the process group leader of a new process group, so it fails in that case).