4

Is there a way to pass data (ex: int value) from one process to another process in c?

In my experience, we just can send signal from one process to another. But looks like there is no way to "attach" some information along with that signal to another process.

1
  • 3
    Even if you couldn't attach data to signals, you could still use signals, transmitting one bit at a time via SIGUSR1 and SIGUSR2... ;-) Commented Nov 24, 2010 at 3:31

5 Answers 5

2

With the sigqueue function, you can pass a single integer or pointer along with a signal (but keep in mind, pointers will be useless if the target of the signal is another process, since different processes don't share address space).

Some other methods are pipes, shared memory (POSIX or SysV style), files, ...

Sign up to request clarification or add additional context in comments.

Comments

2

You can use one of the various Inter Process Communication Mechanisms available.

Use Google. As a reference you can also look here

Comments

0

A clean, portable, powerful way is use Socket.

Comments

0

You can use pipes to do that. The main purpose of pipes is to communicate data between different processes.

Pipes are the simplest mechanism offered by the operating system for inter-process communication. A pipe is a communication buffer between two processes: it has two descriptors, one for writing another for reading. Write and read operations are done in a FIFO order (first-in-first-out).

There are two kinds of pipes: unnamed pipes and named pipes (also known as FIFOs).

  • Unnamed pipes only allow communication between hierarchically related processes (parent and child processes);
  • Named pipes allow the communication between any process. A special file is created in the file-system through

If you want some example code just go here: http://pastebin.com/1W216nyN

Comments

-2

I think we can use global variable between process, not sure but. If any one tried then please let me know. If we use a header which contain extern valriable , we can use this in another main() which is nothing but a independednt program (process). but we have to link the two main() together which executing.

1 Comment

No you can't, processes memory spaces are isolated from each other. The externclause is used to declare external variables from other compilation unit (source file). <br/>And you cannot "link" two main() functions.