|
|
Up |
|
|
  |
Author: smartysmarty Date: May 13, 2008 00:11
can any one tell me what's wrong with this program?
#include
#include
main()
{
int pid,fd,pd;
pid=fork();
char *data,*str="child writes to the file";
if(pid == 0)
{
printf("IN CHILD\tcreating a file to COMMUNICATE\n"...
|
| Show full article (1.41Kb) |
|
| | 7 Comments |
|
  |
Author: chander.kashyapchander.kashyap Date: May 13, 2008 00:28
On May 13, 12:11 pm, smarty gmail.com> wrote:
> can any one tell me what's wrong with this program?
>
> #include
> #include
> main()
> {
> int pid,fd,pd;
> pid=fork();
> char *data,*str="child writes to the file";
> if(pid == 0)
> {
> printf("IN CHILD\tcreating a file to COMMUNICATE\n");
> fd=open("sarma.c",O_CREAT|O_APPEND|O_RDWR);
> perror("OPEN OPERATION");
> write(fd, str , 50);
> perror("WRITE OPERATION");
> fsync(fd);
> perror("FSYNC OPERATION");
> close(fd); ...
|
| Show full article (1.77Kb) |
|
| | no comments |
|
  |
Author: chander.kashyapchander.kashyap Date: May 13, 2008 00:30
On May 13, 12:11 pm, smarty gmail.com> wrote:
> can any one tell me what's wrong with this program?
>
> #include
> #include
> main()
> {
> int pid,fd,pd;
> pid=fork();
> char *data,*str="child writes to the file";
> if(pid == 0)
> {
> printf("IN CHILD\tcreating a file to COMMUNICATE\n");
> fd=open("sarma.c",O_CREAT|O_APPEND|O_RDWR);
> perror("OPEN OPERATION");
> write(fd, str , 50);
> perror("WRITE OPERATION");
> fsync(fd);
> perror("FSYNC OPERATION");
> close(fd); ...
|
| Show full article (1.67Kb) |
| no comments |
|
  |
Author: Spiros BousbourasSpiros Bousbouras Date: May 13, 2008 01:01
On 13 May, 08:11, smarty gmail.com> wrote:
> can any one tell me what's wrong with this program?
>
> #include
> #include
> main()
> {
> int pid,fd,pd;
> pid=fork();
> char *data,*str="child writes to the file";
> if(pid == 0)
> {
> printf("IN CHILD\tcreating a file to COMMUNICATE\n");
> fd=open("sarma.c",O_CREAT|O_APPEND|O_RDWR);
> perror("OPEN OPERATION");
> write(fd, str , 50);
> perror("WRITE OPERATION");
> fsync(fd);
> perror("FSYNC OPERATION");
> close(fd); ...
|
| Show full article (2.00Kb) |
| no comments |
|
  |
Author: Jens Thoms ToerringJens Thoms Toerring Date: May 13, 2008 01:29
smarty gmail.com> wrote:
> can any one tell me what's wrong with this program?
Several things already with your use of C. And then it
uses lots of system specific extensions which should be
discussed in a group that deals with programming for
POSIX systems like comp.unix.programmer. I will try to
concentrate on the C specific issues here (as far as that
can be untangled). Correct those and then ask for further
help in the above mentioned group.
> #include
> #include
These are both non-standard C headers. While I
have no idea what you need for you
will need some more of these system specific
headers, e.g. , and
.
And you need a C standard header
#include
for prototypes for printf() and perror().
|
| Show full article (4.02Kb) |
| no comments |
|
  |
Author: CBFalconerCBFalconer Date: May 13, 2008 07:27
smarty wrote:
>
> can any one tell me what's wrong with this program?
>
> #include
> #include
> main()
To start with, neither of those include files exist in standard C.
At the same time, lacking an include of , I suspect you
will have a hard time getting any data into or out of your
program. After that, main returns an int, and is better written as
"int main(void)".
|
| |
| no comments |
|
  |
Author: Kenneth BrodyKenneth Brody Date: May 14, 2008 13:55
smarty wrote:
>
> can any one tell me what's wrong with this program?
>
[...]
> char *data,*str="child writes to the file";
[...]
> read(pd,data,50);
[...]
> Segmentation fault
>
> what is this segmentation fault for?
Well, ignoring all the non-standard parts of the program, your
problem comes down to the above 2 lines. You have passed read()
an uninitialized pointer, causing the read (if it succeeds) to
overwrite who-knows-what.
|
| Show full article (0.80Kb) |
| no comments |
|
  |
|
|
  |
Author: Antoninus TwinkAntoninus Twink Date: May 15, 2008 15:04
On 13 May 2008 at 7:11, smarty wrote:
> can any one tell me what's wrong with this program?
>
> #include
> #include
Firstly, some missing headers (unistd.h and stdio.h).
Secondly, this should give you some hints of where to look for problems:
$ valgrind ./a >/dev/null
==14808== Memcheck, a memory error detector.
==14808== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et
al.
==14808== Using LibVEX rev 1804, a library for dynamic binary...
|
| Show full article (5.62Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|