Qiang has asked for the wisdom of the Perl Monks concerning the following question:
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
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 ?#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: weird kids process, why ?
by bluto (Curate) on Jan 10, 2005 at 23:31 UTC | |
by Qiang (Friar) on Jan 12, 2005 at 04:39 UTC | |
by Qiang (Friar) on Jan 11, 2005 at 05:32 UTC | |
|
Re: weird kids process, why ?
by jonadab (Parson) on Jan 10, 2005 at 23:53 UTC | |
by Qiang (Friar) on Jan 11, 2005 at 05:40 UTC |