Sponsored Content
Full Discussion: Help about bash process
Top Forums Shell Programming and Scripting Help about bash process Post 302871911 by yanglei_fage on Thursday 7th of November 2013 09:07:59 AM
Old 11-07-2013
Help about bash process

I have function f1 and f2, I want it excute five items with different function in the list the the same time with process.

I did a testing in start_build_feature1, it sleep about 100s, in the sleeping start_build_feature2 print nothing, can someone help me modify this scripts

I don't when start_build_feature1 in the 100s sleep, start_build_feature2 do noting (nothing output in the screen) , I want somthing is parallel

please help me modify and explain it to me



Code:
start_build_feature1()
{
	sleep 100
	echo $1
}

start_build_feature2()
{
	echo $1
}

feature_single1="aa bb c d e f g h i g k l m n u v w x y z"
feature_single2="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"



f1()
{
        pid_feature1=()
        local i
        set -- $feature_single1 # NOte $lists IS NOT QUOTED here.

        while [ "$#" -gt 0 ]
        do
                [ ! -z "$1" ] && ((i += 1)) && start_build_feature1 "$1" & pid_feature1[$i]=$!
                [ ! -z "$2" ] && ((i += 1)) && start_build_feature1 "$2" & pid_feature1[$i]=$!
                [ ! -z "$3" ] && ((i += 1)) && start_build_feature1 "$3" & pid_feature1[$i]=$!
                [ ! -z "$4" ] && ((i += 1)) && start_build_feature1 "$4" & pid_feature1[$i]=$!
                [ ! -z "$5" ] && ((i += 1)) && start_build_feature1 "$5" & pid_feature1[$i]=$!
                shift 5
                for i in ${#pid_feature1[@]}
                do
                        wait ${pid_feature1[$i]}
			echo "start another five in feature_single1"
                done
        done
}

f2()
{
        pid_feature2=()
        local i
        set -- $feature_single2 # NOte $lists IS NOT QUOTED here.

        while [ "$#" -gt 0 ]
        do
                [ ! -z "$1" ] && ((i += 1)) && start_build_feature2 "$1" & pid_feature2[$i]=$!
                [ ! -z "$2" ] && ((i += 1)) && start_build_feature2 "$2" & pid_feature2[$i]=$!
                [ ! -z "$3" ] && ((i += 1)) && start_build_feature2 "$3" & pid_feature2[$i]=$!
                [ ! -z "$4" ] && ((i += 1)) && start_build_feature2 "$4" & pid_feature2[$i]=$!
                [ ! -z "$5" ] && ((i += 1)) && start_build_feature2 "$5" & pid_feature2[$i]=$!
                shift 5
                for i in ${#pid_feature2[@]}
                do
                        wait ${pid_feature2[$i]}
			echo "start another five in feature_single"
                done
        done
}
f1 &
f2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

starting a bash session as child process to another bash session from a process

Hi I want to do something that might sound strange. I have a code that in written in C and is executed at startup (it's a custom process). It occasionally calls some bash scripts. The process doesn't have any terminal associated with it. One thing I don't know how to do is to start a... (5 Replies)
Discussion started by: alirezan
5 Replies

2. Shell Programming and Scripting

Catching SIG of running process with bash

Hello all! I'm writing a script that will catch when an outside process crashes (SIGHUP, right?) without having to loop into infinity. With that in mind, I came across the trap utility and thought if could be used to monitor another process other than it's own. But from what I've read, I'm... (1 Reply)
Discussion started by: mashiox
1 Replies

3. Cybersecurity

Take over a Bash-process.

Hi! I'm not really sure if this is the right forum to post this thread in but I'll try anyway. I was just wondering if it's possible to "take over" a Bash process? For example, if a user is logged in to my server (where I'm root) can I then somehow "clone" his session so I can see what he's... (1 Reply)
Discussion started by: k1piee
1 Replies

4. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

5. Shell Programming and Scripting

bash: closing file descriptors from a process

Below is a test script to illustrate a problem from a larger script I am writing. $ cat /tmp/loggingtest #!/bin/bash lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") sync & wait lvremove -f... (1 Reply)
Discussion started by: jelloir
1 Replies

6. Shell Programming and Scripting

Bash process output analysis

Looking to create a script to listen to each output from a task while it is running and launch a function if a specific error message is found at any point and if not to continue uninterrupted. #!/bin/bash read checker <<< $(reaver -i mon0 -b 'target bssid' -vv) if ; then function elif... (1 Reply)
Discussion started by: 3therk1ll
1 Replies

7. Shell Programming and Scripting

Killing a bash process and running the second part of script

I want to run a script that calls remote ssh and if it gets hung, I want to be able to kill that part of the script and run another command in the script for example I have a statement like this: if ]; then export tapes=$(for tape in $(su - nacct -c 'ssh remote1 "cat... (1 Reply)
Discussion started by: newbie2010
1 Replies

8. Shell Programming and Scripting

Bash-awk to process thousands of files

Hi to all, I have thousand of files in a folder with names with format "FILE-YYYY-MM-DD-HHMM" for what I want to send the following AWK command awk '/Code.*/' FILE-2014* I'd like to separate all files that have the same date to a folder named with the corresponding date. For example, if I... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

9. Shell Programming and Scripting

Bash process timer

I have a bash with several processes in it, that I would like to include a progress bar or percentage complete. Below are two separate processes that, so the user knows that something is happening, there is an an indicator for each process. Maybe, at the start of each new process a printf the... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

Use the get and post method in the bash ( multi process)?

hi I want to call a lot of links with the post method What to do to speed it up?? ####This method is slow #!/bin/bash func2() { index1=0 while read line ; do index1=$(($index1+1)) url=$line done < tmp/url1.txt } (10 Replies)
Discussion started by: mnnn
10 Replies
sleep(1)						      General Commands Manual							  sleep(1)

NAME
sleep - Suspends execution for at least the specified time SYNOPSIS
sleep seconds STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: sleep: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
Non-negative integer specifying the number of seconds for which execution is to be suspended. DESCRIPTION
The sleep command suspends execution of a process for at least the interval specified by seconds, which can range from 0 to 2,147,483,647 seconds. Depending on system activity, the actual time of suspension may be longer. See the sleep(3) reference page. [Tru64 UNIX] seconds can be entered as a non-negative decimal, octal, or hexadecimal value. NOTES
If sleep receives a SIGALARM signal before process execution has resumed, sleep takes one of the following actions: Terminates normally with a 0 (zero) exit status. (See the sleep(3) reference page for more information.) Ignores the signal Performs default processing EXIT STATUS
The following exit values are returned: Execution was successfully suspended for at least the requested time, or a SIGALARM signal was received. An error occurred. EXAMPLES
To display a message at 4-minute intervals for 20 minutes, create a shell script called remind containing the following: for i do sleep 240; echo $i sleep 240; echo $i sleep 240; echo $i sleep 240; echo $i sleep 240; echo $i done To display the message Try calling NHK at 4-minute intervals, enter: remind 'Try calling NHK' To run a command at regular intervals, create a shell script containing the following: while true do date sleep 60 done This displays the date and time once a minute. To execute a command after a specified interval, enter the following; (sleep 3600; echo Time's up) & This displays the message "Time's up" after one hour. ENVIRONMENT VARIABLES
The following environment variables affect the execution of sleep: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for- mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: wait(1) Functions: alarm(3), pause(3), sigaction(2), sleep(3) Standards: standards(5) sleep(1)
All times are GMT -4. The time now is 09:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy