1838105 Members
3614 Online
110124 Solutions
New Discussion

Thread, exec bug

 
Erich Hochmuth
Occasional Contributor

Thread, exec bug

I think I???ve ran into a problem with the latest patch to libcma.1 (PHSS_23672) on HPUX 10.20
I was wandering if any one has run into a similar problem?

I have a program that creates a thread and then in the main thread execs another program.
When the thread is created the main program gets a ???Virtual time alarm??? signal before it gets a chance to exec the program. If I forego creating the thread my program execs the second program no problem.

When I take out the patch (PHSS_23672) and go to prior patch level (PHSS_15731-32) my program can exec other programs with out any problem, regardless if I have created a thread.

WITH OUT THE THREAD
$ ./mymain 0 ps
PID TTY TIME COMMAND
15956 pts/0 0:00 ps
15243 pts/0 0:00 sh

WITH THE THREAD
$ ./mymain 1 ps
Virtual time alarm
$

PROGRAM SOURCE
#include
#include
#include
#include
#include
#include
#include

void *thread_function(void *args);

int main(int argc, const char *argv[])
{
pthread_t t;
if (argv[1][0] == '1')
{
if (pthread_create(&t, pthread_attr_default, thread_function, NULL) != 0)
{
printf("Could not create pthread, errno = %d!\n", errno);
exit(1);
}
}

char *program_and_args[20];
char program[256];
char args[256];

memcpy(program,'\0',256);
memcpy(args,'\0',256);
strcpy(program,argv[2]);
strcpy(args,argv[3]);

program_and_args[0] =
(char*)malloc(strlen(program)*sizeof(char) + sizeof(char));
strcpy(program_and_args[0],program);

program_and_args[1] =
(char*)malloc(strlen(args)*sizeof(char) + sizeof(char));
strcpy(program_and_args[1],args);

execvp(program,program_and_args);

return 0;
}

void *thread_function(void *args)
{
printf("Thread created\n");
while (1);
return NULL;
}

Thanks in advance for any help,
Erich