Run 4-processes concurrently


 
Thread Tools Search this Thread
Top Forums Programming Run 4-processes concurrently
# 8  
Old 03-02-2006
Use threads .

John Arackal
# 9  
Old 03-03-2006
you have the answer,

at the prime level - parent
fork four process concurrently and not hierarchical forking ( as that would extend to grandchild ... relation )

then bind each of the function to each of the child process created and let the parent wait for the return status of the child.

Is that what you want? else
be elaborate !!!
# 10  
Old 03-03-2006
ugp, please read our rules which state:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.


This was a good example of what happens when you break that rule. Folks were struggling with your your 4 threads trying to figure out what you wanted. I have merged your 4 threads into one thread. I'm also a little afraid that you are violating rule 6. But you have been at this for weeks and I would think any classroom deadline has passed.

Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

#define NUM_CHILDREN 4


main()
{
        pid_t children[NUM_CHILDREN];
        int i;
        setvbuf(stdout, NULL, _IONBF, 0);

        for(i=0;i<NUM_CHILDREN;i++){
                if( (children[i]=fork()) == 0 ){
                                printf("I am child number %d and my pid is %d \n", i, getpid());
                                exit(0);
                } else {
                        sleep(2);
                        printf("I am the parent \n");
                }
        }
        exit(0);
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run feeding each other processes simultaneously?

Hello, I need to run multiple shell processes simultaneously and output of the first process shall be the input of the second process but first process is never ending so both should be running in parallel. I do not wish to wait the end of the first process. I am under ubuntu 16.04. ... (3 Replies)
Discussion started by: baris35
3 Replies

2. UNIX for Dummies Questions & Answers

Maximum no of processes that can run

Is there any limit in UNIX that only a MAXIMUM no of processes can run at a time? If so, it exceeds then what would be the error we would receive? (4 Replies)
Discussion started by: jansat
4 Replies

3. UNIX for Dummies Questions & Answers

How to run script concurrently

Hi all, I have one script. Its job is to get 1 file from dirA and 1 file from dirB as parameters for another python script. However, there are a lot of files in both dir A and B, so running this scripts really takes a lot of time. So I wonder if there are any ways that I can do this faster,... (6 Replies)
Discussion started by: yoyomano
6 Replies

4. UNIX and Linux Applications

how to run more than two processes parallely

I would like to call a function called CIRCLE which is further beind called by other function but in a loop that CIRCLE fuction is being called. And this CIRCLE function starts another process which takes 3 hours to complete again, if i put that process in nohup &, I can go to the next command... (2 Replies)
Discussion started by: venugopalsmartb
2 Replies

5. Shell Programming and Scripting

kill my processes which are run by hacker

how can I kill my processes which are run by hacker or another person who log in with my username and password (1 Reply)
Discussion started by: thsecmaniac
1 Replies

6. Programming

how to run socket programme and file management concurrently

hi i have a server socket programme which is running in HP/UX system and then need to add a function about refreshing memory every miniute because the socket programme is blocked , i have no idea about this what should i do thanks (10 Replies)
Discussion started by: benbenpig
10 Replies

7. UNIX for Advanced & Expert Users

script to run different shells which run different processes

Hi, Would like to ask the experts if anyone knows how to run a script like this: dtterm -title shell1 run process1 on shell1 dtterm -title shell2 run process2 on shell2 cheers! p/s: sorry if i used the wrong forum, quite concussed after watching world cup for several nights; but I... (2 Replies)
Discussion started by: mochi
2 Replies

8. UNIX for Advanced & Expert Users

Run away processes

Hi, My server runnning on SUN Solaris rel.5.5.1. I have been facing this issues for years. I have some Xbase databases running on the server. User is using emulation software to telnet to server for accessing application. If user logout application abnormally - by closing windows session, then... (2 Replies)
Discussion started by: lowtaiwah
2 Replies

9. UNIX for Advanced & Expert Users

preventing others to run processes on my machine

I am in a multi-user Linux environment at work. Other users easily run processes on my machine when my machine is idle, but when I try to use my machine, it is dead slow. The processes run by them always grab the top spot using 99% of my CPU time. Is there a way I can prevent others to run... (3 Replies)
Discussion started by: besharam
3 Replies

10. Shell Programming and Scripting

How to run processes in parallel?

In a korn shell script, how can I run several processes in parallel at the same time? For example, I have 3 processes say p1, p2, p3 if I call them as p1.ksh p2.ksh p3.ksh they will run after one process finishes. But I want to run them in parallel and want to display "Process p1... (3 Replies)
Discussion started by: sbasak
3 Replies
Login or Register to Ask a Question