LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2006, 09:59 PM   #1
ugp
LQ Newbie
 
Registered: Feb 2006
Posts: 7

Rep: Reputation: 0
how to differentiate processes


how to differentiate processes

If there are 1-parent & 4-concurrent same level children, how to differntiate those

processes.
I.e: 4 child processes should able to call diffenent functions.

Child1 should call function-A while
Child2 should call function-B
Child3 should call function-c
Child4 should call function-D


Can i use pid of processes to do this...
If so how???

Are there any other method.
 
Old 03-02-2006, 01:31 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,818

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
Need more info: how are the processes created, what lang eg C using fork ?
 
Old 03-02-2006, 01:52 AM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
yes it is fork()
fork that many process from the same level
and not subsequent forking ( that would establish parent-child-grandchild--)

hence fork from the first level itself.

after forking bind each of the function to each of the child.
 
Old 03-02-2006, 02:36 AM   #4
ugp
LQ Newbie
 
Registered: Feb 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01
Need more info: how are the processes created, what lang eg C using fork ?

Here, according to this code it create 4 concurrent children.


#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

main(){
int pid;
int i;
for (i = 1; i <= 4; i++){
if(pid != 0)
pid = fork();

}

sleep(10);
}



From those 4 processes i need to use one process as "RECEPTIONIST" & other three as "AGENTS".
To do so, how can i differentiate the processes.
RECEPTIONIST should read from a file and should send those to message queue.
AGENTS should read from that message queue.
(I need to have 1 RECEPTIONIST FUNCTION & 1 AGENT FUNTION.So to which process i should write those functions)

How can i do that...
 
Old 03-02-2006, 11:41 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,818

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
From the fork() manpage:

RETURN VALUE
On success, the PID of the child process is returned in the parent’s
thread of execution, and a 0 is returned in the child’s thread of exe-
cution. On failure, a -1 will be returned in the parent’s context, no
child process will be created, and errno will be set appropriately.

so you just check the rtn code from the fork() call, which tells you which process each code is running in.
Call fork() 3 times to use each child as an AGENT, & parent as RECEPTIONIST.
This isn't a homework qn by any chance ...?
 
Old 03-03-2006, 12:45 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,782

Rep: Reputation: 481Reputation: 481Reputation: 481Reputation: 481Reputation: 481
ugp, your program has a bug, pid is not initialized when used for the first time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How many processes does everyone have? Furlinastis Slackware 22 09-26-2005 03:53 AM
Too much processes barghota Linux - General 5 07-02-2005 10:40 AM
monitoring active processes and identifying the required processes. gajaykrishnan Programming 2 08-13-2004 02:58 AM
How to differentiate between binary, source and package/installer? subaruwrx Linux - Software 19 06-21-2004 11:12 AM
Too many processes? mooreted Linux - Software 2 04-05-2004 04:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration