Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* fork debugging : back to parent.
@ 2006-08-07 20:21 Richard (sent by Nabble.com)
  2006-08-07 21:07 ` Daniel Jacobowitz
  2006-08-10 21:06 ` Richard
  0 siblings, 2 replies; 11+ messages in thread
From: Richard (sent by Nabble.com) @ 2006-08-07 20:21 UTC (permalink / raw)
  To: gdb


Below is the code from "Advanced programming in the Unix environment". if I
set follow-fork to child, I can step ok to the exclp line. But how do I get
back to debugging the parent process? Is it possible? I tried setting
follow-fork back to "parent" and then "c"ontinuing but no joy.  or do I have
to specifically save process ids and reattach to the parent process?

=======
#include "apue.h"
#include <sys/wait.h>

int
main(void)
{
	char	buf[MAXLINE];	/* from apue.h */
	pid_t	pid;
	int		status;

	printf("%% ");	/* print prompt (printf requires %% to print %) */
	while (fgets(buf, MAXLINE, stdin) != NULL) {
		if (buf[strlen(buf) - 1] == '\n')
			buf[strlen(buf) - 1] = 0; /* replace newline with null */

		if ((pid = fork()) < 0) {
			err_sys("fork error");
		} else if (pid == 0) {		/* child */
			execlp(buf, buf, (char *)0);
			err_ret("couldn't execute: %s", buf);
			exit(127);
		}

		/* parent */
		if ((pid = waitpid(pid, &status, 0)) < 0)
			err_sys("waitpid error");
		printf("%% ");
	}
	exit(0);
}
-- 
View this message in context: http://www.nabble.com/fork-debugging-%3A-back-to-parent.-tf2067795.html#a5693501
Sent from the gdb - General forum at Nabble.com.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-08-10 22:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-07 20:21 fork debugging : back to parent Richard (sent by Nabble.com)
2006-08-07 21:07 ` Daniel Jacobowitz
2006-08-07 21:47   ` Richard
2006-08-08  0:04     ` Daniel Jacobowitz
2006-08-08  7:27       ` Richard
2006-08-08  8:49       ` Richard
2006-08-08 13:16         ` Daniel Jacobowitz
2006-08-10 21:06 ` Richard
2006-08-10 21:39   ` Daniel Jacobowitz
2006-08-10 22:06     ` Richard
2006-08-10 22:10       ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox