Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 May 2004 11:57:54 +1000
From:      Tim Robbins <tjr@freebsd.org>
To:        threads@freebsd.org
Subject:   execve() and KSE
Message-ID:  <20040520015754.GA2572@cat.robbins.dropbear.id.au>

next in thread | raw e-mail | index | archive | help
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);
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040520015754.GA2572>