Vittal <vs*********@yahoo.com> wrote:
Here I have a simple C program. But I am not understanding how I can
debug this?
#include <stdio.h>
main()
{
int pid=0;
pid=fork();
if(pid)
printf("In parent process\n");
else
printf("In child process\n");
}
While running the executable in dbx mode I see the first printf
statement and after that sample directly comes out. But if I run the
executable without dbx I see both the printf statements.
Sorry, but this is off-topic in comp.lang.c - the C standard never
talks about fork() or having more than one process running at once.
You'll be better served in e.g. comp.unix.programmer where UNIX
specific extensions like fork() to the C language are discussed.
The only standard C specific problem of your code is that you
don't declare main() as returning int as you ought to (at least
if you want to avoid trouble with C99 compilers) and that you
forgot to return an int from main() (which you must, because
even if you don't specify a return type for main() under C89 it
defaults to int).
<OT>
First, you need to include also <unistd.h> for the prototype of
fork(). It's also recommended to use the 'pid_t' type for PIDs.
And, second, your program is working exactly as it is supposed
to work, you spawn a second process which prints one line while
the parent process prints the other one. If you run the whole
thing under a debugger it might grab the terminal so only the
process you're running under the control of the debugger may be
able to get its message printed. Hopefully, the documentation
for your debugger will give you all the gory details.
</OT>
Regards, Jens
--
_ _____ _____
| ||_ _||_ _|
Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | |
http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring