Sponsored Content
Top Forums Shell Programming and Scripting Keep a certain number of background processes running Post 302280631 by dgob123 on Tuesday 27th of January 2009 10:00:03 AM
Old 01-27-2009
Keep a certain number of background processes running

I've got a bit of code I'm trying to work on...
What i want to happen is ... at all times have four parallel mysql dump and imports running.

I found the follow code snippet on the forum and modified it to work
by starting four concurrent processes but it waits until all four are done before starting the next four...

Code:
 
LIST='wmi_product wmi_patches employee actions jobs appversions os hardware detection_apps status wmi_networkadapterconfig wmi_logicaldisk'
let counter=0;
for i in $LIST
do
   echo "    Dumping and Importing table $i" " ( `date +'%x %X'` ) "
   $MYSQLDUMP -h$DBHOST -u$USER -p$PASSWORD -q --opt --single-transaction --add-drop-table $DB --tables $i | $MYSQL -u$DBuser -p$DBpass $DB > $ilog.txt &
    let counter=$counter+1
    echo "$counter%4" | bc
    if [ `echo "$counter%4" | bc` -eq 0 ] ; then
          wait
    fi
done;

Is there a way to do this?
Any help would be appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running two processes in background

hi there, here's what i need in my korn-shell: ... begin korn-shell script ... nohup process_A.ksh ; nohup process_B.ksh & ... "other stuff" ... end lorn-shell script in plain english i want process A and process B to run in the background so that the script can continue doing... (6 Replies)
Discussion started by: jacob_gs
6 Replies

2. Shell Programming and Scripting

Determine Number of Processes Running

I am pretty new to unix, and I have a project to do. Part of the project asks me to determine the number of processes running and assign it to a variable. I know how to every part of the project but determine the number of processes running. How can I get just the number of processes... (4 Replies)
Discussion started by: wayne1411
4 Replies

3. Solaris

About running processes in background

Hi, I need to establish a procedure that will start an application in background each time my remote Solaris server is (re)started. This would be a kind of daemon. I am no sysadmin expert, so I am looking for pointers. How should I proceed? What are the main steps? Thanks, JVerstry (9 Replies)
Discussion started by: JVerstry
9 Replies

4. Shell Programming and Scripting

Waiting for an arbitrary background process (limiting number of jobs running)

Hi, I'm trying to write a script to decompress a directory full of files. The decompression commands can run in the background, so that many can run at once. But I want to limit the number running at any one time, so that I don't overload the machine. Something like this: n=0 for i in *.gz... (15 Replies)
Discussion started by: p.f.moore
15 Replies

5. Shell Programming and Scripting

Background Processes

Ok guys so I have my first dummy shell almost done except for one tiny part: I do not know how to run a process in the background, from the code! I already know how to do that in a normal shell: $ program & However, no clue when it comes to how to program that thing. :eek: A very... (2 Replies)
Discussion started by: Across
2 Replies

6. Shell Programming and Scripting

How to Control Number of Processes Running

Hi Is there a way to count how many processes a script has started, count how many of these have finished, and make the script wait if their difference goes over a given threshold? I am using a script to repeatedly execute a code (~100x) which converts 2 data files into one .plt which is in... (4 Replies)
Discussion started by: drbones
4 Replies

7. UNIX for Dummies Questions & Answers

Query on Running Multiple processes in background

HI All , Pardon me for asking some very basic questions, I would be grateful if someone can help. I am trying to execute a shell script which runs multiple processes in background. It includes various operations like copying , DB operations etc etc. Now problem is that the complete script... (6 Replies)
Discussion started by: gpta_varun
6 Replies

8. UNIX for Dummies Questions & Answers

How do you print the number of processes that each user is currently running in Unix?

Ok, so I know there's a way to do this, but I've been trying to find out all afternoon with no luck. I think it should print out something like this: 1 bin 2 daemon 6 duo Where the numbers on the left are the number of processes being run by the user whose name is listed on the right. Is... (4 Replies)
Discussion started by: Duo11
4 Replies

9. Shell Programming and Scripting

Need help on background processes

Hi, I have a schell script parent.ksh from which I am calling three background processes a.ksh,b.ksh and c.ksh. Once these three processes completes the next step in parent.ksh should execute. How to achieve this? Please help me.... Thanks... (1 Reply)
Discussion started by: ravinunna
1 Replies

10. UNIX for Dummies Questions & Answers

How do I find the number of processes running on root?

Is there a certain man command I'm missing here? I searched in ps but I couldn't find something that would give me the number of processes running on root. I only want to see the number of processes, not the processes itself. (2 Replies)
Discussion started by: l3monz
2 Replies
PMC_CONTROL(2)						      BSD System Calls Manual						    PMC_CONTROL(2)

NAME
pmc_control, pmc_get_info -- Hardware Performance Monitoring Interface LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/pmc.h> int pmc_control(int ctr, int op, void *argp); int pmc_get_info(int ctr, int op, void *argp); DESCRIPTION
pmc_get_info() returns the number of counters in the system or information on a specified counter ctr. The possible values for op are: PMC_INFO_NCOUNTERS When querying the number of counters in the system, ctr is ignored and argp is of type int *. Upon return, the integer pointed to by argp will contain the number of counters that are available in the system. PMC_INFO_CPUCTR_TYPE When querying the type of a counter in the system, ctr refers to the counter being queried, and argp is of type int *. Upon return, the integer pointed to by argp will contain the implementation-dependent type of the specified counter. If ctr is -1, the integer pointed to by argp will contain the machine-dependent type describing the CPU or counter configuration. PMC_INFO_COUNTER_VALUE When querying the value of a counter in the system, ctr refers to the counter being queried, and argp is of type uint64_t *. Upon return, the 64-bit integer pointed to by argp will contain the value of the specified counter. PMC_INFO_ACCUMULATED_COUNTER_VALUE When querying the value of a counter in the system, ctr refers to the counter being queried, and argp is of type uint64_t *. Upon return, the 64-bit integer pointed to by argp will contain the sum of the accumulated values of specified counter in all exited sub- processes of the current process. pmc_control() manipulates the specified counter ctr in one of several fashions. The op parameter determines the action taken by the kernel and also the interpretation of the argp parameter. The possible values for op are: PMC_OP_START Starts the specified ctr running. It must be preceded by a call with PMC_OP_CONFIGURE. argp is ignored in this case and may be NULL. PMC_OP_STOP Stops the specified ctr from running. argp is ignored in this case and may be NULL. PMC_OP_CONFIGURE Configures the specified ctr prior to running. argp is a pointer to a struct pmc_counter_cfg. struct pmc_counter_cfg { pmc_evid_t event_id; pmc_ctr_t reset_value; uint32_t flags; }; event_id is the event ID to be counted. reset_value is a value to which the counter should be reset on overflow (if supported by the implementation). This is most useful when profiling (see PMC_OP_PROFSTART, below). This value is defined to be the number of counter ticks before the next overflow. So, to get a profiling tick on every hundredth data cache miss, set the event_id to the proper value for ``dcache-miss'' and set reset_value to 100. flags Currently unused. PMC_OP_PROFSTART Configures the specified ctr for use in profiling. argp is a pointer to a struct pmc_counter_cfg as in PMC_OP_CONFIGURE, above. This request allocates a kernel counter, which will fail if any process is using the requested counter. Not all implementations or coun- ters may support this option. PMC_OP_PROFSTOP Stops the specified ctr from being used for profiling. argp is ignored in this case and may be NULL. RETURN VALUES
A return value of 0 indicates that the call succeeded. Otherwise, -1 is returned and the global variable errno is set to indicate the error. ERRORS
Among the possible error codes from pmc_control() and pmc_get_info() are [EFAULT] The address specified for the argp is invalid. [ENXIO] Specified counter is not yet configured. [EINPROGRESS] PMC_OP_START was passed for a counter that is already running. [EINVAL] Specified counter was invalid. [EBUSY] If the requested counter is already in use--either by the current process or by the kernel. [ENODEV] If and only if the specified counter event is not valid for the specified counter when configuring a counter or starting profiling. [ENOMEM] If the kernel is unable to allocate memory. SEE ALSO
pmc(1), pmc(9) HISTORY
The pmc_control() and pmc_get_info() system calls appeared in NetBSD 2.0. BSD
October 27, 2005 BSD
All times are GMT -4. The time now is 05:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy