Sponsored Content
Top Forums Shell Programming and Scripting Controlling the Number of Child processes Post 302922856 by APT_3009 on Tuesday 28th of October 2014 05:49:49 PM
Old 10-28-2014
Controlling the Number of Child processes

I am trying to implement the below using Ksh script on a Lx machine.

There is a file(input_file) with 100K records. For each of these records, certain script(process_rec) needs to be called with the record as input. Sequential processing is time-consuming and parallel processing would eat up resources.
I would like to ensure that at any given time there are exactly 10 processes running. The problem with using wait command is that it waits until all child processes are over.

For example - If first 10 records are being processed by 10 child processes, I would like that if any 1 of the child process completes, a new child process gets started processing the 11th record from the input_file.

How could this be achieved?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Controlling processes knowing the PID's

Dear all, suppose that I start a process (named "father"). "father" starts in turns a process called "child" with an execv call (after a fork). In this way "father" will be notified if "chlid" crashes (SIGCHILD mechanism). The problem is: if "father" crashes, how can I do to be recreate a... (1 Reply)
Discussion started by: npalmentieri
1 Replies

2. UNIX for Dummies Questions & Answers

what are parent and child processes all about?

I don't follow what these are... this is what my text says... "When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)
Discussion started by: xyyz
1 Replies

3. Programming

Controlling child processes

Hello all, I am trying to create n child processes and control them from a parent process; say make child 3 print its pid and then child 5 do the same and some other stuff. Is there a way to accomplishing this after all the child processes are created via a call to fork(). Thank you, FG (23 Replies)
Discussion started by: forumGuy
23 Replies

4. Shell Programming and Scripting

Parent/Child Processes

Hello. I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors? Thanks (2 Replies)
Discussion started by: yoi2hot4ya
2 Replies

5. Programming

fork() and child processes

Hello, How many child processes are actually created when running this code ? #include <signal.h> #include <stdio.h> int main () { int i ; setpgrp () ; for (i = 0; i < 10; i++) { if (fork () == 0) { if ( i & 1 ) setpgrp () ; printf ("Child id: %2d, group: %2d\n", getpid(),... (0 Replies)
Discussion started by: green_dot
0 Replies

6. UNIX for Advanced & Expert Users

killing all child processes

Hi, Is there a way I can kill all the child processes of a process, given its process id. Many thanks in advance. J. (1 Reply)
Discussion started by: superuser84
1 Replies

7. Programming

How to limit the number of child processes

I need a mechanism to fork child processes and all child processes should connect to a server.but the number of child processes should be limited(for ex:50) Here's my pseudo, but I cant figure out how to limit the child process number. Should I use a semaphore? or what? for(;;)... (3 Replies)
Discussion started by: xyzt
3 Replies

8. Programming

Controlling a child's stdin/stdout (not working with scp)

All, Ok...so I know I *should* be able to control a process's stdin and stdout from the parent by creating pipes and then dup'ing them in the child. And, this works with all "normal" programs that I've tried. Unfortunately, I want to intercept the stdin/out of the scp application and it seems... (9 Replies)
Discussion started by: DreamWarrior
9 Replies

9. Windows & DOS: Issues & Discussions

Controlling AIX processes remotely using a NET app on a Windows server?

I have a .NET application that remotely starts, stops, and gets status of Windows services and scheduled tasks. I would like to add the capability of starting, stopping, and getting status of remote AIX applications also. Based on some preliminary research, one option may be to use 3rd party .NET... (0 Replies)
Discussion started by: auser1
0 Replies

10. Shell Programming and Scripting

Get all child processes of a process

is there a universal way of getting the children of a particular process? i'm looking for a solution that works across different OSes...linux, aix, sunos, hpux. i did a search online and i kept finding answers that were specific to Linux..i.e. pstree. i want to be able to specify a process... (2 Replies)
Discussion started by: SkySmart
2 Replies
waitid(2)							System Calls Manual							 waitid(2)

NAME
waitid - wait for child process to change state SYNOPSIS
DESCRIPTION
The function suspends the calling process until one of its children changes state. It records the current state of a child in the structure pointed to by infop. If a child process changed state prior to the call to returns immediately. The idtype and id arguments are used to specify which children will wait for. If idtype is will wait for the child with a process ID equal to (pid_t)pid. If idtypeis will wait for any child with a process group ID equal to (pid_t)pid. If idtypeis will wait for any children and id is ignored. The options argument is used to specify which state changes will wait for. It is formed by OR-ing together one or more of the following flags: Wait for processes that have exited. Status will be returned for any child that has stopped upon receipt of a signal. Status will be returned for any child that was stopped and has been continued. Return immediately if there are no children to wait for. Keep the process whose status is returned in infop in a waitable state. This will not affect the state of the process; the process may be waited for again after this call completes. The infop argument must point to a structure. If returns because a child process was found that satisfied the conditions indicated by the arguments idtype and options, then the structure pointed to by infop will be filled in by the system with the status of the process. The si_signo member will always be equal to RETURN VALUE
If returns due to the change of state of one of its children, 0 is returned. Otherwise, -1 is returned and is set to indicate the error. ERRORS
The function will fail if: [ECHILD] The calling process has no existing unwaited-for child processes. [EINTR] The function was interrupted due to the receipt of a signal by the calling process. [EINVAL] An invalid value was specified for options, or idtype and id specify an invalid set of processes. APPLICATION USAGE
Threads Considerations In a multi-threaded application, only the calling thread is suspended by will not return until all threads in the process have reached the desired state. For example, if the or options are specified, will not return until all threads in the process have terminated, stopped or continued respectively. SEE ALSO
exec(2), exit(2), wait(2), <sys/wait.h>. CHANGE HISTORY
First released in Issue 4, Version 2. waitid(2)
All times are GMT -4. The time now is 11:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy