execve() and KSE
Tim Robbins
tjr at freebsd.org
Wed May 19 18:56:17 PDT 2004
What is supposed to happen when a threaded process (linked with libpthread)
calls execve()?
The program attached to this message seems to execute "true" correctly, but
it never returns to the shell I invoked it from. ^T shows it in the state
"running", and the system load average approaches 1.00:
load: 0.15 cmd: true 726 [running] 0.00u 0.00s 0% 200k
load: 0.56 cmd: true 726 [running] 0.00u 0.00s 0% 200k
load: 0.91 cmd: true 726 [running] 0.00u 0.00s 0% 200k
However, it's not using any CPU according to %CPU:
$ ps -Haxo pid,%cpu,mwchan,state,command -p 726
PID %CPU MWCHAN STAT COMMAND
726 0.0 - RL+ true
The system is FreeBSD 5.2-CURRENT/amd64 with a kernel from May 9, and with
WITNESS and INVARIANTS both turned off. I'll try updating and re-enabling
the diagnostic options later today.
Here's the code in question:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static pthread_cond_t cond;
void *
thrstart(void *a)
{
pthread_cond_wait(&cond, NULL);
if (execl("/usr/bin/true", "true", NULL) < 0)
perror("execl");
return (NULL);
}
int
main(int argc, char *argv[])
{
void *v;
pthread_t t1;
pthread_cond_init(&cond, NULL);
pthread_create(&t1, NULL, thrstart, NULL);
pthread_cond_broadcast(&cond);
pthread_join(t1, &v);
exit(0);
}
More information about the freebsd-threads
mailing list