Sponsored Content
Top Forums Programming Creating 3 process and piping a message Post 302330317 by p00ndawg on Tuesday 30th of June 2009 09:05:14 PM
Old 06-30-2009
Quote:
Originally Posted by tetsujin
OK, first off, you've got a total of four processes here, not three... (Is that what you wanted? For the process I call A to spawn off three children? Or did you want three processes total?)

Process A (original process): pid = B, pid1 = C
Process B (first child of A): pid = 0, pid1 = D
Process C (second child of A): pid = B, pid1 = 0
Process D (child of B): pid = 0, pid1 = 0



This if statement will actually run for three of the four processes: A, C, and D:
Process A: (pid | pid1 == 0) = (B | C == 0) = (B | 0) = true
Process B: (pid | pid1 == 0) = (0 | D == 0) = (0 | 0) = false
Process C: (pid | pid1 == 0) = (B | 0 == 0) = (B | true) = true
Process D: (pid | pid1 == 0) = (0 | 0 == 0) = (0 | true) = true
(where true is some nonzero value...)



p[2] is uninitialized. pipe() only creates two file descriptors: p[0], the read end of the pipe, and p[1], the write end of the pipe.

Also, from the problem description it sounded like you wanted each of the three communicating processes to have the ability to write messages to and receive messages from each of the other two communicating processes. This suggests you need to create at least three pipes (three invocations of pipe() in the parent process). I say "at least three pipes" because if these processes are running concurrently, allowing two processes to write to the same file descriptor could have unpredictable results. (Using write() to write a single, whole message will probably be safe - but if the message were large it's possible the write would block waiting for the reader to read some data out - in which case I think it's possible the other process's write() could wind up getting in before the first write() finishes its message. (Not sure, though. write() is a system call so the kernel may synchronize it...)

Remember that pipe() creates two file descriptors but just one pipe. A pipe with an input end and an output end. A file descriptor you get from pipe() is either read-only or write-only - you can never read and write from the same file descriptor, when the file descriptor was obtained with pipe().
yes I actually wanted processes A, B, and C communicating with each other, but I only wanted to pipe a message from a->b->c. I didnt realize I had created 4 processes.
Is there anyway to just create 3 processes? how about a way to just get variable pipes communicating with each other?

Thanks for the awesome breakdown.

Last edited by p00ndawg; 06-30-2009 at 10:29 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirection or piping error message

I have written a script that appears to work correctly in testing, but is coming up with a starnge error message, script_name: test: 0403-004 Specify a parameter with this command. Redirection or piping of stdin or stdout is allowed only with -b. (156). The script is run by different... (2 Replies)
Discussion started by: mariner
2 Replies

2. Programming

creating child process

i want to create 3 child processes from the same parent using folk. I know how to use folk but my child processes did not come from the same parent. Any suggestion what i did wrong ? (12 Replies)
Discussion started by: Confuse
12 Replies

3. Shell Programming and Scripting

creating 10 process

can anyone tell me how to Create ten processes and display useful information about them including PID, starting-time in unix using c or c++ language. i tried to create 10 different processes using fork and exec but i couldn't display those process info:PID,STIME. my sample code ......... (2 Replies)
Discussion started by: kpkant123
2 Replies

4. Programming

message queues and multi-process

Hi, Am supposed to use message queues to send and receive messages between the processes. when i was working on that i realised that the message qid and the message queue related data should be maintained in a shared memory so that it can be accessed by all the processes. Could anybody refer... (10 Replies)
Discussion started by: rvan
10 Replies

5. Programming

URGENT:::Can anybody help me in creating message queue appliction??

hello, I had to implement a message queue application....between 30 processes...... all 30 proceses are getting data from serial port.... And here is THE FLOW::::::::1 connector process...which is linked with message queue to all the 30 applications. Processes get the data from serial port and... (9 Replies)
Discussion started by: arunchaudhary19
9 Replies

6. Shell Programming and Scripting

How to get rid of message when script kills process it started?

When I run the following script I get the following error message whcih I would like to suppress when the kill is issued: ./kill.sh: line 13: 31854 Killed nc -l -p 12345 Script: #!/bin/bash echo running nc in the background nc -l -p 12345 & PID=$! echo nc pid: $PID ... (1 Reply)
Discussion started by: cmarkle
1 Replies

7. Programming

Permission denied when creating message queue

Hi guys. i have wrote a simple program to test message queue attributes. here it is: #include <stdio.h> #include <stdlib.h> #include <mqueue.h> #include <fcntl.h> #include <string.h> #include <errno.h> #include <sys/stat.h> int main() { struct mq_attr attr; mqd_t mqd; ... (2 Replies)
Discussion started by: majid.merkava
2 Replies

8. Programming

creating a message queue using mq_open

Hi all, First of all thanks in advance for reading my post and for your heart for helping me. I am trying to create a message queue using mq_open(name,oflags,mode_t,attr) method. But that function call is returning with an error code EFAULT. By googling it I found that it happens when there is... (10 Replies)
Discussion started by: parusasi
10 Replies

9. Shell Programming and Scripting

Getting warning message while creating a file thru script

I have a script, it will create 3 files --------- file1=dataout/file1.txt file2=dataout/file2.txt file3=dataout/file3.txt echo "0" > $file3 --------- For file1 and file2 we are not initializing any values. But for file3 we are initializing the value of 0. When we execute the... (3 Replies)
Discussion started by: kmanivan82
3 Replies

10. AIX

Process using/creating files in the filesystem

Hello Team, In a application filesystem, there is a process keep creating the log files. Due to that the filesystem keep getting full. Please let me know how to identify the process which is keep writing in the filesystem. fuser -u <FS> will show only the user who using the filesystem.... (3 Replies)
Discussion started by: gowthamakanthan
3 Replies
KILLALL5(8)						Linux System Administrator's Manual					       KILLALL5(8)

NAME
killall5 -- send a signal to all processes. SYNOPSIS
killall5 -signalnumber [-o omitpid[,omitpid..]] [-o omitpid[,omitpid..]..] DESCRIPTION
killall5 is the SystemV killall command. It sends a signal to all processes except kernel threads and the processes in its own session, so it won't kill the shell that is running the script it was called from. Its primary (only) use is in the rc scripts found in the /etc/init.d directory. OPTIONS
-o omitpid Tells killall5 to omit processes with that process id. NOTES
killall5 can also be invoked as pidof, which is simply a (symbolic) link to the killall5 program. EXIT STATUS
The program return zero if it killed processes. It return 2 if no process were killed, and 1 if it was unable to find any processes (/proc/ is missing). SEE ALSO
halt(8), reboot(8), pidof(8) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl 04 Nov 2003 KILLALL5(8)
All times are GMT -4. The time now is 03:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy