gdb에서.. fork을 이용해 두가지로 나누어지는 프로세스...

익명 사용자의 이미지

통신 프로그램에서 fork을 이용해 부보 프로세스 와 자식 프로세스로 나누
어 지는데 이것을 gdb로 어떻게 돌아 가는지 보려고 하는데요
fork에서 나누어지는 두개의 프로세서중 자신이 보려고 하는 부분을 찿아
서 gdb로 돌리려면 어떻게 해야 하는지 궁금해요(부모 프로세스를 선택할
것인가 아니면 자식 프로세서를 선택할것인가를 선택하게 해주는 gdb옵션)
알고 있는 분이 있다면 제발 알려주세요

익명 사용자의 이미지

## Debugging programs with multiple processes
GDB has no special support for debugging programs which
create additional processes using the fork function. When a
program forks, GDB will continue to debug the parent
process and the child process will run unimpeded. If you
have set a breakpoint in any code which the child then
executes, the child will get a SIGTRAP signal which (unless
it catches the signal) will cause it to terminate.

However, if you want to debug the child process there is a
workaround which isn't too painful. Put a call to sleep in
the code which the child process executes after the fork.
It may be useful to sleep only if a certain environment
variable is set, or a certain file exists, so that the
delay need not occur when you don't want to run GDB on the
child. While the child is sleeping, use the ps program to
get its process ID. Then tell GDB (a new invocation of GDB
if you are also debugging the parent process) to attach to
the child process (see section Debugging an already-running
process). From that point on you can debug the child
process just like any other process which you attached to.

## Debugging an already-running process

attach process-id
This command attaches to a running process--one that was
started outside GDB. (info files shows your active
targets.) The command takes as argument a process ID. The
usual way to find out the process-id of a Unix process is
with the ps utility, or with the `jobs -l' shell command.
attach does not repeat if you press RET a second time after
executing the command.
To use attach, your program must be running in an
environment which supports processes; for example, attach
does not work for programs on bare-board targets that lack
an operating system. You must also have permission to send
the process a signal.

When using attach, you should first use the file command to
specify the program running in the process and load its
symbol table. See section Commands to specify files.

The first thing GDB does after arranging to debug the
specified process is to stop it. You can examine and modify
an attached process with all the GDB commands that are
ordinarily available when you start processes with run. You
can insert breakpoints; you can step and continue; you can
modify storage. If you would rather the process continue
running, you may use the continue command after attaching
GDB to the process.

detach
When you have finished debugging the attached process, you
can use the detach command to release it from GDB control.
Detaching the process continues its execution. After the
detach command, that process and GDB become completely
independent once more, and you are ready to attach another
process or start one with run. detach does not repeat if
you press RET again after executing the command.
If you exit GDB or use the run command while you have an
attached process, you kill that process. By default, GDB
asks for confirmation if you try to do either of these
things; you can control whether or not you need to confirm
by using the set confirm command (see section Optional
warnings and messages).

익명 사용자의 이미지

님의 답변 감사 합니다
저는 읽어 봐도 무슨 말인징 잘 모르겠어
저 혹시 sleep의 사용법을 알수 있을까요?

익명 사용자의 이미지

#include

main()
{
if(fork()==0){
sleep(30); /* 30초간 슬립*/
printf("child\n");
} else {
printf("parent\n");
}
}

이런식으로 자식에 슬립을 주시고
ps -ef | grep 프로세스네임

예 httpd란 이름일때,,

ps -ef f| grep httpd

root 20443 1 0 Apr11 ? S
000 /usr/local/apache/bin/httpd
nobody 20793 20443 0 Apr11 ? S 021
\_ /usr/local/apache/bin/httpd
nobody 20794 20443 0 Apr11 ? S 020
\_ /usr/local/apache/bin/httpd
nobody 20795 20443 0 Apr11 ? S 020
\_ /usr/local/apache/bin/httpd
nobody 20796 20443 0 Apr11 ? S 022
\_ /usr/local/apache/bin/httpd
nobody 20797 20443 0 Apr11 ? S 025
\_ /usr/local/apache/bin/httpd
nobody 20799 20443 0 Apr11 ? S 022
\_ /usr/local/apache/bin/httpd
nobody 20800 20443 0 Apr11 ? S 022
\_ /usr/local/apache/bin/httpd
nobody 20801 20443 0 Apr11 ? S 028
\_ /usr/local/apache/bin/httpd
nobody 20938 20443 0 Apr11 ? S 018
\_ /usr/local/apache/bin/httpd

[root@hyuna fboard]# gdb
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i386-redhat-linux".
(gdb) attach 20793

Attaching to Pid 20793
0x406d69e2 in ?? ()

이런식으로 자식 pid를 알아야 가능하죠
아니면 ps -ef 쓰지말고... getpid시스템 콜을 사용하셔서
슬립 들어 가기전에 printf로 출력하시던지요;;

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.