#!/perl/me -w
use strict;
use FileHandle;
my $i = 0;
# Get the current Process Id
my $proc = getpgrp(0);
# Create 10 files..
while ($i < 10) {
# Get a new File Handle
my $fh = new FileHandle();
# Count the File Handle for this process...
system ("ls -l /proc/$proc/fd/ | wc -l");
# Open a new File
sysopen ($fh, "/tmp/$i", O_RDWR) or die "$!";
# Write something to the file
print $fh "stuff \n";
#increment counter, to create a newer file.
$i++;
## NO CLOSE...
}
/tmp> ./perl junk2.pl
5
5
5
5
5
5
5
5
5
5
I was expecting it to go UP by 1 each time in the loop, but it stayed at 5. Why?
20100721 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.