arm: getpid() when creating a new process with clone, getpid() returns a wrong pid.
wangyufen
wangyufen at huawei.com
Sat Aug 30 09:05:44 UTC 2014
Called getpid() When creating a new process with clone(), getpid() returns the father_process's value.
It should be child_process's value.
I use that code do test:
#include <errno.h>
#include <stdio.h>
#include <sched.h>
#include <string.h>
#define CHILD_STACK_SIZE 16384
int child_fn(void *test)
{
printf("child=%d\n", getpid());
exit(1);
}
int main(int ac, char **av)
{
int TEST_RETURN;
void *child_stack; /* stack for child */
int child_pid;
/* Allocate stack for child */
if ((child_stack = (void *)malloc(CHILD_STACK_SIZE)) == NULL) {
exit(1);
}
TEST_RETURN = clone(child_fn, child_stack + CHILD_STACK_SIZE, 0, NULL);
printf("clone return=%d\n", TEST_RETURN);
if (TEST_RETURN == -1) {
exit(1);
}
printf("father=%d\n", getpid());
return 0;
}
compiled that code with -g -lpthread, run, child pid is wrong
#arm-linux-uclibceabi-gcc -g -lpthread -o test1 test.c
# ./test1
clone return=406
child=405
father=405
compiled that code with -g , run, child pid is OK
#arm-linux-uclibceabi-gcc -g -o test test.c
-bash-4.2# ./test
clone return=404
child=404
father=403
I do some strace and gdb on test1 and test, test uses syscall getpid(), test1(compiled with -lpthread) get pid from [r2, #-1060]
More information about the uClibc
mailing list