All pastes #93246 Raw Edit

fifo_consumers

public shellscript v1 · immutable
#93246 ·published 2006-07-20 09:28 UTC
rendered paste body
#!/bin/bashmax_session=5my_wd=$(pwd)if [ -z $1 ] ; then	my_session=1else	my_session=$(( $1 + 1 ))ficreate_producer(){	if [ ! -p $my_wd/iofifo ] ; then		mkfifo $my_wd/iofifo	fi	while read line ; do echo $line > $my_wd/iofifo ; done < liste &}init_session(){	# session initialisation w/ the processing server	echo "$my_session : init_session"}process_line(){# arg : $1  : line to process	echo "my session processing :  $1"}close_session(){	echo "[7m$my_session : close_session[0m"	exit}fct_cleanup(){	if [ $my_session -ne 1 ]; then		kill -s SIGUSR1 $PPID		fi	close_session}trap "fct_cleanup" SIGHUP SIGINT SIGQUIT SIGILL SIGABRT SIGFPE SIGUSR1 SIGUSR2 SIGPIPE SIGTERMread_iofifo(){	echo "Hello I'm Here"	if [ -f $my_pwd/all_lines_processed ] ; then		kill -s SIGUSR1 $PPID	fi	read line < iofifo	if [ $line == 'Finish' ] ; then # Finish is the last file's line to process		kill -s SIGUSR1 $$	else		process_line $line	fi}if [ $my_session == 1 ] ; then	create_producerfiecho "Hello - my pid is $$"echo "my parent is $PPID"if [[ $my_session -lt $max_session ]] ; then	$0 $my_session $my_duty_max $_duty_marker fiinit_sessionwhile read myline ; do	process_line $mylinedone < <(read_iofifo)