Check if Queue empty or full in perl

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check if Queue empty or full in perl
# 1  
Old 09-28-2011
Check if Queue empty or full in perl

Hi, I got problem with queue code how to determined empty and full and problem with while loop

Here is my pseudo code :
Input page Access
Input Pgae Frame
For i =3 to pageframe count by 1
  construct queue of size i
  set pageFaultCount to 0
   while morepages do
       page = NextPage
       if queue.isINqueue <-- page then
          do nothing
          if queue.isFull then
             queue.dequeue <-- page
             queue.enqueue <-- pageFaultCount  
             add 1 to pageFaultCount
   end while
   output pagefault for i frames
end for

perl code :
#!usr/bin/perl -w
use Thread::Queue;

print "Enter require page";
chomp(my $page = <STDIN>);
my @page = split(' ', $page);
print "Enter upperBound";
chomp(my $bound = <STDIN>);
 for ($i1 = 3; $i1<= $bound;$i1++)
    my $queue = Thread::Queue->new($bound);
     my @queue = split(' ', $queue);
     $size = @queue;
    my $pageFaultCount = 0;
    my $nextpage = 0;
       while ( $page >= 0 )
    if ()
    do nothing
               $page = $page + $nextpage;

                if(@queue >= $size)
                    $pageFaultCount = $pageFaultCount + 1;
             print " $pageFaultCount for $i1 Frames\n";        
      }# end if
   } # end while
     } # End for


Last edited by vbe; 09-28-2011 at 12:31 PM.. Reason: indentation of pseudocode
# 2  
Old 09-28-2011
Compared to your pseudocode, why is the last print statement included in the last Endif instead of after the end-while? or which is the correct form you wish...

Last edited by vbe; 09-28-2011 at 12:41 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check mail queue

We use Redhat server , we always use mailq to check any pending mail in mailq , when run the command mailq , it shows all existing pending mail would advise how to write a script to show the pending mails which are older than 24 hours , ( if possible , then send this pending mail info to... (9 Replies)
Discussion started by: ust3
9 Replies

2. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies

3. Shell Programming and Scripting

queue problem perl

Hi, I have implement queue but it take last element instead of fist element #!/usr/bin/perl -w print "Enter page Access"; chomp ($item = <STDIN>); my @queue = split /\s+/, $item; print "Enter a page frame"; $frame = <STDIN>; if ( $frame >= 3 ) { $fifo = pop @queue; print... (1 Reply)
Discussion started by: guidely
1 Replies

4. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

5. Shell Programming and Scripting

Empty buffer when is full

Hello everyone! This is the situation: I execute this command from a bash script: telnet 6001 >> output.txt The question is: How I do to execute this command and empty the buffer when is full? The script is always running. Thanks a lot! (2 Replies)
Discussion started by: bobbasystem
2 Replies

6. Shell Programming and Scripting

check if file is empty

How do I check if a file is empty in a sh script I want to test in my shell script if the output file is empty and if it is do one thing and if it isnt empty do another? any ideas? (8 Replies)
Discussion started by: stolz
8 Replies

7. UNIX for Dummies Questions & Answers

How to Turn perl one-liners into full perl script?

I have the following command prompt perl one liner: perl -e 's/\(\)\\,\"]//g; s/^\s//g; s/;/\n/g' -pi result1 I tried to move this one liner into a perl script I am practicing with (just started learning perl right now). I tried the following (I only know how to open a file and output to a... (1 Reply)
Discussion started by: EDALBNUG
1 Replies

8. UNIX for Dummies Questions & Answers

How to check if a file is empty?

Hi Masters..... I have problem !!! I need to check number of records in a file and if it is zero or file is empty i need to do some task. if ; then echo "File s empty" else echo "Not empty" fi so how to check this condition. I used wc -l < filename.txt => 1 for zero records same result... (1 Reply)
Discussion started by: shreekrishnagd
1 Replies

9. UNIX for Dummies Questions & Answers

How to check for empty file in Perl?

Hi, May I know how to check for empty file in Perl. Iam missing something, somewhere. #!/usr/bin/perl my $open_dir = '/path/'; my $file; my $ma = "abc_.*.\.psv\$" opendir(VAR, $open_dir) or die "Can't open $oepn_dir: $!\n"; while( defined ($file = readdir VAR) ) #read all... (1 Reply)
Discussion started by: deepakwins
1 Replies

10. Shell Programming and Scripting

Check for empty string

Hello All, I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline... (12 Replies)
Discussion started by: rahman_riyaz
12 Replies
Login or Register to Ask a Question