LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2008, 11:11 PM   #31
cocchiararo
LQ Newbie
 
Registered: Apr 2008
Posts: 29

Original Poster
Rep: Reputation: 15

we ended up using read -t, but ill inform my group about the other sugestions that may be usefull if our actual choise has problems.

pd: will try your exact code to see if i did anything wrong last time :P

EDIT: you where right, it works, dunno why it didnt work last time :P

Last edited by cocchiararo; 05-05-2008 at 11:21 PM.
 
Old 05-16-2008, 01:35 PM   #32
cocchiararo
LQ Newbie
 
Registered: Apr 2008
Posts: 29

Original Poster
Rep: Reputation: 15
big trouble !

we thought we were done, but when we tested the periodic functions (setting them to run each second), we discovered that the signals/traps we were using cause a segmentation fault and everything falls appart

here is an example that causes the crash:
Code:
#!/bin/bash
declare -r tmpoV=1 #this sets how often verificar.sh has to run
declare -r tmpoA=1 #this sets how often admin_modulos_per.sh has to run
FactCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'` #this is used to collect the actual modification date of a bunch of files, and store the newest

Tver () {
. /usr/bin/verificar.sh
}
Tadm_per () {
. /usr/bin/Desktop/admin_modulos_per.sh
}

/usr/bin/control_tmpo.sh $$ $tmpoV "USR1" &
/usr/bin/control_tmpo.sh $$ $tmpoA "USR2" &

trap Tver "USR1"
trap Tadm_per "USR2"

while true
do
read Com
done
control_tmpo looks like this:
Code:
#!/bin/bash

while true
do
sleep $2
kill -s $3 $1
done
verificar:
Code:
#!/bin/bash
FmodCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'`
if [ "$FactCfgs" != "$FmodCfgs" ]
FactCfgs=$FmodCfgs
echo -e -n "\nSthere is a change in the config files, executing regiter and initialize modules\n"
. /usr/bin/reg_e_ini_modulos.sh
fi
admin_modules_per
Code:
#!/bin/bash

for x in `seq 1 ${#ModuloP[*]}`
do
	${ModuloP[$x-1]} Procesar
	if [ $? = 1 ]
	then
		echo "A periodic module failed"
		echo "A periodic module failed" >> /home/$USER/periodicos.log
		exit 1
	fi
done
If we set 1 of the periodic functions not to run, nothings bad happens. If we set both with the same time, it crashes really fast. If we use diferent times, eventually, they try to run at the same time, and for some reason verificar.sh runs while admin_modulos_per.sh is runing (the for cicle was not done), and administrar never ends... then the next time administrar wants to run... segmentation fault.
My partner discovered that if we just put 2 similar senteces inside admin_modulos_per and verificar, it crashes too, he thinks its related to using `` in assignations.
Code:
FmodCfgs=`ls -tcRn --full-time /etc/michelle | grep -w "$USER"$'\n'"periodicos.config"$'\n'"comando.config" -m 1 | awk '{print $6$7}'`
and we put something similar (or identical) in the other script, and everything still falls appart.. but if we dont use that or the `seq 1 ${#ModuloP[*]}`, it doesnt crash :/

are we doing something weird/wron with the signals ? we read that signals/traps dont interrupt each other, if one is running, the other just waits.

a capture of the "error""
Code:
[michelle]zero@debian:~$ /usr/bin/verificar.sh: line 2: wait_for: No record of process 841
Violación de segmento
Violacion de segmento = Segmentation fault

EDIT: also, we found that if we put sleep 1, or just a=a or whatever != than read inside the while cicle, there seems to be no problem :/ (but we need the read in the first place, its a read-eval loop :P )

Last edited by cocchiararo; 05-16-2008 at 01:43 PM.
 
Old 05-16-2008, 05:16 PM   #33
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I guess the code implementing the `` operator is not reentrant (i.e. doesn't like getting interrupted).

For this particular case you can rewrite
Code:
for x in `seq 1 ${#ModuloP[*]}`
as
Code:
 for ((x=1; x <= ${#ModuloP[*]}; x++)) ; do
But that's not a very satisfying solution. You could try implementing mutual exclusion in bash, or maybe avoid using traps after all.
 
Old 05-16-2008, 05:47 PM   #34
cocchiararo
LQ Newbie
 
Registered: Apr 2008
Posts: 29

Original Poster
Rep: Reputation: 15
we tried mutual exclusion (we just had the class about IPC, sincronization, etc :P), but no go.

then my teammate changed the control_tmpo.sh and verificar.sh way of working, now there are no sleeps, and everything is fine... but we always use a little cpu :P
 
  


Reply

Tags
scripting, shell



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Linux Shell instead of bash/sh CY83R-R0N1N Linux - General 5 02-15-2007 05:15 PM
Linux Bash shell Scrpt help samBl Linux - General 3 08-29-2006 05:29 PM
Posting guidelines... Answering guidelines? itsjustme LQ Suggestions & Feedback 14 07-22-2005 01:08 PM
Linux Shell Scripting using BASH Help! fooforon Programming 5 02-05-2004 09:16 AM
Looking for a good list of shell commands with examples jk1 Linux - Newbie 4 06-11-2002 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration