file sharing in linux
  Home FAQ Contact Sign in
comp.lang.c only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c Profile…
 Up
file sharing in linux         


Author: smarty
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
Re: file sharing in linux         


Author: chander.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
Re: file sharing in linux         


Author: chander.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
Re: file sharing in linux         


Author: Spiros 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
Re: file sharing in linux         


Author: Jens 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
Re: file sharing in linux         


Author: CBFalconer
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)".

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

** Posted from http://www.teranews.com **
no comments
Re: file sharing in linux         


Author: Kenneth 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
Re: file sharing in linux         


Author: Antoninus 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
SubjectArticles qty Group
PASS Test-File-Cleaner-0.03 i686-linux-64int 2.6.22-1-k7perl.cpan.testers ·