473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

What happend with parent process.

What happend with parent proces.
Two scripts:

perl4:
Expand|Select|Wrap|Line Numbers
  1. #
  2. # loop operations
  3. #
  4. use strict;
  5. my @food;
  6. my $morsel;
  7. my $TableLength;
  8. my $i;
  9. @food = ("pear", "plum", "egg", "apple");
  10. #
  11. # Table printing
  12. #
  13. $TableLength = $#food;
  14. print $TableLength;
  15. foreach $i (@food){
  16.     print $i."\n";
  17. }
  18. do
  19. {
  20.     print "Password?";
  21.     $a = <STDIN>;
  22.     chop $a;
  23. }
  24. while ($a ne "fred");
perl5:
Expand|Select|Wrap|Line Numbers
  1. # Variable declaration
  2. my $FileName = "perl4.pl";
  3. my $Line = "";
  4. my @Table;
  5. my $pid;
  6.  
  7. $pid = system $FileName;
  8.  
  9. if(not defined $pid){
  10. #child
  11.    print "no resources";
  12. }elsif($pid == 0)
  13. {   
  14.     print "I am a child";
  15.     STDOUT->autoflush();
  16.     sleep(5);
  17.     print "I am a child2\n";
  18. }else{
  19.     print "I am a parent";
  20.     STDOUT->autoflush();
  21. }
printout:
prear
plum
egg
apple
Password?fred
I am a childI am a child2

And I have no output from parent process. Can anybody explain me why?
Mar 1 '08 #1
1 957
KevinADC
4,059 Expert 2GB
In your program, $pid is the return value of the system() function, which is the value of wait(), which is the value of the deceased forked process, which must be 0 (zero) judging by the behavior of your program. You are also using the autoflush() method without loading the IO::Handle module, which should cause your script to abort.

See, your program is not checking if a process is a child or a parent, it is only checking the return value of the system() function.
Mar 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: nicver | last post by:
I am fixing a client's Web site and I do not have the time to reprogram things my way, and the last hurdle I have is with a piece of javascript embedded in an ASP snippet. The payment form is...
4
by: Mayolo Juarez via DotNetMonster.com | last post by:
Hi, I have a problem, when i use a context menu in a MDIForm and activate the property "MDIList= True", the context menu don't show me the current child windows, please help me, i use VS2003. ...
13
by: Jimmy Cracker | last post by:
Is it completely impossible in UNIX to push an environment variable to the parent shell? I would like to do something like this: main(int argc, char *argv) { char *var; var = (char...
1
by: Shark | last post by:
What could be the error?? i have a dll for converting vox files to Dll. the structure of the header looks like : ...
3
by: bp4444 | last post by:
On a HPUX, a CPP program. In main() defined a variable as int x = 900, called fork(), changed value of x as 89 in child process. Printed the address of x and value of x in child process and also...
1
by: thunder54007 | last post by:
hi, here is my script: import win32con import time import wmi c = wmi.WMI() for process in c.Win32_Process(name = "notepad.exe"): print process.ProcessId, process.Name process.Terminate ()
0
by: kreismaler | last post by:
I have some problems to understand the difference of using the STDOUT and using "anonymous pipes" as shown below: using System; using System.Diagnostics; using System.IO; namespace...
1
by: KakaICE | last post by:
Hi, I am using Visual Studio 2005 The problem is: The parent.exe launches a child.exe executible. In the child.exe process I want to know the commandline with which parent.exe was originally...
1
by: subrahmanya | last post by:
Hi All A process spawns another process and it inherits all the parent process handles. While the child process is existing if parent process closes a file handle will the corresponding handle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.