Hello, Monks I am having this weird problem with forking.

what i am doing during each child process is to chown directories with corresponding uid and gid and few other external commands.

to my surprise, the chown command in one child process changed the directory in other child process. I did `ls` to the working dir and you can see the directories' owner ship keep chaning. here is the demostration.

sunsplash:~# ls -l /home/grad/c total 28 drwx------ 3 angelop employee 4096 Jan 10 17:23 abunting drwx------ 3 angelop employee 4096 Jan 10 17:23 aer drwx------ 3 angelop employee 4096 Jan 10 17:23 alison3 drwx------ 3 angelop employee 4096 Jan 10 17:23 alitvak drwx------ 3 angelop employee 4096 Jan 10 17:23 angelad drwx------ 3 angelop employee 4096 Jan 10 17:23 angelop drwxr-xr-x 3 root root 4096 Jan 10 17:23 anistasi sunsplash:~# ls -l /home/grad/c total 48 drwx------ 3 bookoff misc 4096 Jan 10 17:23 abunting drwx------ 3 anistasi employee 4096 Jan 10 17:23 aer drwx------ 3 anistasi employee 4096 Jan 10 17:23 alison3 drwx------ 3 anistasi employee 4096 Jan 10 17:23 alitvak drwx------ 3 bookoff misc 4096 Jan 10 17:23 angelad drwx------ 3 anistasi employee 4096 Jan 10 17:23 angelop drwx------ 3 anistasi employee 4096 Jan 10 17:23 anistasi drwx------ 3 anistasi employee 4096 Jan 10 17:24 asantili drwx------ 3 anistasi employee 4096 Jan 10 17:24 banfield drwxr-xr-x 3 root root 4096 Jan 10 17:24 bbatke drwxr-xr-x 3 root root 4096 Jan 10 17:24 bigdaddy drwxr-xr-x 3 root root 4096 Jan 10 17:25 bookoff sunsplash:~# ls -l /home/grad/c total 48 drwx------ 3 bookoff misc 4096 Jan 10 17:23 abunting drwx------ 3 bigdaddy employee 4096 Jan 10 17:23 aer drwx------ 3 bigdaddy employee 4096 Jan 10 17:23 alison3 drwx------ 3 bigdaddy employee 4096 Jan 10 17:23 alitvak drwx------ 3 bookoff misc 4096 Jan 10 17:23 angelad drwx------ 3 anistasi employee 4096 Jan 10 17:23 angelop drwx------ 3 anistasi employee 4096 Jan 10 17:23 anistasi drwx------ 3 anistasi employee 4096 Jan 10 17:24 asantili drwx------ 3 anistasi employee 4096 Jan 10 17:24 banfield drwxr-xr-x 3 root root 4096 Jan 10 17:24 bbatke drwxr-xr-x 3 root root 4096 Jan 10 17:24 bigdaddy drwxr-xr-x 3 root root 4096 Jan 10 17:25 bookoff
#!/usr/bin/perl -w use strict; use lib "/home/qiang/source"; use Parallel::ForkManager; my $source = "/home/sta/"; my $target = "/home/grad/"; my @source_topdirs = map {$source . $_} ('a'..'z'); my @target_topdirs = map {$target . $_} ('a'..'z'); my $maildir = "Maildir"; my $convert_script = "/home/qiang/m.pl"; my $max_proc = 5; my $pm = new Parallel::ForkManager($max_proc); my $start = scalar localtime(time); foreach my $source_topdir ($source_topdirs[2]) { # usr names under /home/sta/[a-z] my @usr_names = map {chomp;$_} `ls $source_topdir`; # /home/grad/[a-z] my $target_topdir = $target_topdirs[2]; foreach my $usr_name (@usr_names) { my $source_usrdir = $source_topdir . "/" . $usr_name; my $target_usr_maildir = $target_topdir . "/" . $usr_name . "/ +" . $maildir; print "working on $source_usrdir \n"; $pm->start and next; # do the fork # prepare new user mail dir and convert old user dir into it. # &mkdirs_and_convert($target_topdir,$source_usrdir,$target_us +r_maildir); my ($uid,$gid) = (stat $source_usrdir)[4,5]; #print "uid: $uid gid: $gid source: $source_usrdir target: $targe +t_topdir\n"; `/bin/mkdir -p $target_usr_maildir && $convert_script -s $source_usrdir -R -d $target_usr_maildir & +& /bin/chown -R $uid:$gid $target_topdir && /bin/chmod -R 0700 $target_topdir`; $pm->finish; } } $pm->wait_all_children;
before I put all commands in seperate backtick and then I switched , put them in one in hope that would spawn one child and hence nothing would be shared externaly. any ideas ?

In reply to weird kids process, why ? by Qiang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.