UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » How to send a variable in c

#1 2008-11-10 01:47 PM

Umaka
Guest

Re: How to send a variable in c

Hey all, I am doing a unix programming course. I have assignment in C.
I want to know, How can  I send a variable(integer, the index) to the child from the parent.


thank you.

#2 2008-11-10 08:12 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a variable in c

If you need to share variables, it's probably better to use threads instead of child
processes, in general...

However, there are various ways you could transfer arbitrary data (including the
value of a variable) from one process to another: shared memory, pipes, sockets,
etc...  Which one makes the most sense for you will depend on your design...  But,
I'd bet a pipe would probably be simplest...  Before creating your child process,
call pipe() to create a pipe, then fork() and have the child close the write end and
the parent close the read end...  Then, you can just write() whatever data you want
down the pipe from the parent, and have the child read() it...

Offline

  • Index
  • » C
  • » How to send a variable in c

Board footer

Powered by FluxBB