Bug 8921 - setpgid fails from a thread other than main
Summary: setpgid fails from a thread other than main
Status: RESOLVED CODE_FIX
Alias: None
Product: Process Management
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: process_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-22 03:03 UTC by Marcin Kowalczyk
Modified: 2007-09-17 18:36 UTC (History)
2 users (show)

See Also:
Kernel Version: 2.6.21.5
Subsystem:
Regression: ---
Bisected commit-id:


Attachments

Description Marcin Kowalczyk 2007-08-22 03:03:31 UTC
Most recent kernel where this bug did not occur: unknown
Distribution: PLD Linux
Hardware Environment: i686
Software Environment: glibc-2.6.1 (NPTL)
Problem Description: Calling setpgid on a child process by a thread other than the main thread fails with ESRCH.

Steps to reproduce:

#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>

void *thread_body(void *arg) {
   pid_t pid;
   int status;
   (void)arg;
   pid = fork();
   if (pid == 0) {
      sleep(1);
      exit(0);
   }
   if (setpgid(pid, 0) == -1)
      perror("setpgid");
   else
      printf("ok\n");
   return NULL;
}

int main(void) {
   pthread_t th;
   printf("From the main thread\n");
   thread_body(NULL);
   printf("From another thread\n");
   pthread_create(&th, NULL, thread_body, NULL);
   pthread_join(th, NULL);
   return 0;
}

Actual result:

From the main thread
ok
From another thread
setpgid: No such process

Expected result:

From the main thread
ok
From another thread
ok
Comment 1 Andrew Morton 2007-08-22 08:32:15 UTC
What makes you believe that ok+ok is the expected result?
Comment 2 Roland McGrath 2007-08-22 14:42:54 UTC
It's correct that setpgid should work from any thread in the group.
Oleg's patch fixes it.
Comment 3 Randy Dunlap 2007-09-17 18:36:18 UTC
Dnia 22-08-2007, Śr o godzinie 10:30 -0700, Randy Dunlap napisał(a):

> > > so "fixes http://bugzilla.kernel.org/show_bug.cgi?id=8921"  ??
> > 
> > Hopefully yes... should I add some note at /bugzilla.kernel.org?
> 
> I think that it can wait until Marcin confirms that it's fixed
> (if he does so soon), then mark 8921 as fixed.

Yes, it's fixed. Thank you!

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/

Note You need to log in before you can comment on or make changes to this bug.