tags:

views:

132

answers:

1

I want a alternative function call for setpgid to call on a process that has done exec() call. setpgid returns error if it is called on a child which has already called exec. Does any alternative function exists?

A: 

After a successful exec, the process group can only be changed by the process itself. The most straightforward way to change it from another process, if the child is cooperating, would be to use a pipe or other interprocess communication mechanism to ask the child to change its own process group. Another alternative would be to attach to the child process (e.g. with ptrace, gdb, or an OS-specific mechansim) and execute the setpgid() system call from within the context of the child process. Other alternatives such as a new kernel module or modifying kernel memory require root or special system capabilities and are likely to be much worse than the other approaches.

mark4o