This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fork debugging : back to parent.



Incidentally, I also tried "set $tmp=parent_id" (I made an api call to get
the parent proc id in the child fork), and in the child I tried to "attach
$tmp", but it said there was no such process. Is it not possible to use
convenience variables for things like "attach"? "attach parent_id" worked
fine.


Richard wrote:
> 
> 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#a5752608
Sent from the gdb - General forum at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]