Hi,
clone() does get called but with -lpthread it segfaults (currently, only
main() threads core dump; this is being worked on by the LKD's).
(To see this try strace -f ./cl1 )
Anyway, like I asked you in a private message already why would you mix
the clone() system call with libpthread calls (or why else link
libpthread)? At the moment pthread_create is a wrapper for clone().
I guess Mandrake barfs at your cl.c because libsafe is automatically
linked. Playing with header files (adding memory.h) and allocation types
(i.e. valloc???, malloc, alloca, ...) I can get the clone process to run,
so it must be some stack/pointer issue. Normally you should be able to
allocate stack space on the heap but I guess (!!! not sure) libsafe
doesn't like this. Allocating stack space on the stack of the current
thread is obviously allowed since it can be monitored. See attachment.
Unless you are developping a new thread library, I advice you to read the
last part of the clone() man page if you are trying to invent your own
threading wheel...
I think this is not a problem with Mandrake so we should take this
off-list.
Greetings,
Guy
#include <sched.h>
#include <signal.h>
#include <memory.h>
#include <stdio.h>
#define STSZ (4*1024)
int pslave(void *data)
{
puts("slave runs <================");
return 0;
}
int main(int argc,char** argv)
{
char *stack;
stack = (char *)alloca(STSZ);
if (stack == NULL) {
printf ("Not enough memory\n");
exit(1);
}
puts("about to clone...");
clone(pslave, (void *)(stack+STSZ-1), CLONE_VM|CLONE_FILES|SIGCHLD, NULL);
puts("clone ok");
wait(0);
puts("slave done");
/* free(stack);*/
return 0;
}