Help Needed "Urgent"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Needed "Urgent"
# 8  
Old 08-08-2005
Hello ,
Im not from any school , im just learing unix and this an excercise problem from a book, which i was trying for a long time and was unable to get a answer and thought of posting so i may get a solution.

Last edited by warangalboy; 08-11-2005 at 04:17 PM..
# 9  
Old 08-08-2005
Try incorporating the following also in madmat's script.

kill -STOP pid suspend the process and swap it out
kill -CONT pid resume a process previously stopped


You need to get the pid of the new script.

In short, it should be like this.

Code:
Run the new-script.
Get the pid of the new-script.
kill -STOP on pid
sleep for n seconds.
kill -CONT pid

Vino
# 10  
Old 08-08-2005
Hello Vino,
Thanks for the reply,
i have tried the madmat code , but the code runs the script i pass as argument and then sleep , but i want the script to run for second argument seconds and then sleep for second argument seconds and continue till 1st arument script executes and i have been trying in this way

#! /bin/bash

$1 & # run it in background
pid=$! # note it's process ID

i=1 # first state is 1=running
while :; do # endless loop
sleep $2 # wait
ps $pid > /dev/null || break # if no process, the exit loop
test $i -eq 1 \ # if current state is 1=running...
&& kill -SIGSTOP $pid \ #... then stop it...
|| kill -SIGCONT $pid #... else continue
((i=1-i)) # change the state between 1 and 0
done

Can u plz help me
Thanks in advance
# 11  
Old 08-09-2005
Can any plz help
# 12  
Old 08-09-2005
Check this out.

Code:
#! /bin/ksh

if [[ $# -ne 2 ]] ; then
echo "Need just 2 arguments"
exit 1;
fi ;

SCRIPT=${1}
TIME=${2}

echo "$SCRIPT will run for $TIME sec"

$SCRIPT &
pid=$!

while kill -0 $pid 2> /dev/null
do
        kill -s CONT $pid         
        #skill -s CONT -p $pid
        sleep $TIME

        kill -s STOP $pid 2> /dev/null
        #skill -s STOP -p $pid
        sleep $TIME
done ;

Not tested tho'.

If kill -s STOP $pid 2> /dev/null doesnt work then try skill -s STOP -p $pid. and likewise for kill -s CONT


Vino

Last edited by vino; 08-09-2005 at 03:06 AM..
# 13  
Old 08-09-2005
warangalboy, please read our rules. And in particular:
(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.

Both your duplicate thread and your "Can any plz help" post are against that rule. If this is just a problem from some book and not a classwork assignment, can you help me understand the urgency? What would be your idea of a low priority problem?

vino, the "kill -0 $pid" idea is great. That's a much better way to check if the process is still running. But if those kill commands don't work, the skill commands won't help either. Anyway skill won't be on most unix boxes. I have only seen it on Linux.

Complex signals like this do not mix well with many shell scripts. The problem is that shell scripts are a collection of processes, not the single process that you are signalling.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

Help Needed "Urgent"

Im a newbie to Unix Shell Scripting and im trying to solve the problem. can any one plz help. This is the problem. Im trying to write a WW script which takes 2 arguments: 1) the name of some script ($1) and (2) an integer value ($2) WW should execute the specified script for the specified... (2 Replies)
Discussion started by: warangalboy
2 Replies
Login or Register to Ask a Question