What is meant by subprocesses?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What is meant by subprocesses?
# 8  
Old 03-22-2010
Quote:
Originally Posted by Straitsfan
My apologies -- but your explanation is fine. So I'm guessing that a subprocess consists of other executions required to carry out the primary executions of said instructions?
Now I'm the one scratching my head, no idea what you're saying here. Maybe first off we should explain what a process is.

A process is an independent virtual memory space that a program can execute inside. It has its own independent set of memory, set of open files, and its own program context.

You get a sub-process when this process makes the fork() system call. It creates a near-perfect copy of the old process all the way down to open files and what instruction its currently running, with one significant difference: the 'child' process will have zero returned to it from the fork() call, while the 'parent' process will have the new process' PID returned to it. Based on that the same program can take different directions. Also, when the 'child' terminates, the 'parent' is told about it via a signal.

So, they're independent, but may share some things like files, and they know which created which.

The only process with no parent at all is process 1, init. All other processes are created by fork(). So a child process isn't some special kind of process apart, it's just a description of which process created which.

Whenever you run a shell script it's probably running in a sub-process. the shell forks off a new process and runs the script inside it.

Last edited by Corona688; 03-22-2010 at 12:37 PM..
# 9  
Old 03-22-2010
Quote:
Originally Posted by Straitsfan
So I'm guessing that a subprocess consists of other executions required to carry out the primary executions of said instructions?
Maybe although you would need to define what you mean with "executions", "primary executions" and clarify what "said instructions" are referring to.
Quote:
so when something is 'known' to a subprocess, it means what?
Known means well, known, the opposite of unknown. In that context, it means the variable names and contents are reachable and usable by the subprocess.
# 10  
Old 03-22-2010
Quote:
Originally Posted by jlliagre
Maybe although you would need to define what you mean with "executions", "primary executions" and clarify what "said instructions" are referring to.
Known means well, known, the opposite of unknown. In that context, it means the variable names and contents are reachable and usable by the subprocess.
...And the process-fork concept tells you why. The new process gets a copy of the memory of its parent, including environment variables, but after the fork these memory spaces are independent -- changes in either child or parent are not reflected in the other.
# 11  
Old 03-25-2010
In this example script1 invokes script2. Parameters exported from script1 are available to script2.

Code:
#!/bin/ksh
# This is script1
#
# Getting environment variables ready for script2
export myparameter1="first_parameter_for_script2"
export myparameter2="second_parameter_for_script2"
# Invoke the subprocess called script2
# script2 will see all exported environment variables
echo "Starting: script1"
echo "myparameter1=${myparameter1}"
echo "myparameter2=${myparameter2}"
./script2
echo "Finishing: script1"


#!/bin/ksh
# This is script2
#
# Indenting the echoes by 5 spaces for visual effect
echo "     Starting: script2"
echo "     ${myparameter1}"
echo "     ${myparameter2}"
echo "     Finishing: script2"



./script1
Starting: script1
myparameter1=first_parameter_for_script2
myparameter2=second_parameter_for_script2
     Starting: script2
     first_parameter_for_script2
     second_parameter_for_script2
     Finishing: script2
Finishing: script1

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shells, forks, subprocesses... oh my

all, i've been reading to try and get an abstract idea of the process effeciency of commands , sed, bash, perl, awk, find, grep, etc which processes will spawn?, fork?, launch subshell?, etc and under what conditions? how do you know which commands have the faster and better stdio... (2 Replies)
Discussion started by: f77hack
2 Replies

2. UNIX for Dummies Questions & Answers

How to kill a script and all its subprocesses?

I'd like to terminate scripts. These scripts are not by me, but other persons. These contain other programs such as ping, nmap, arp, etc. If such a script is running, how can I terminate this script AND all processes called by this script? These scripts are big so terminating all programs... (4 Replies)
Discussion started by: lordofazeroth
4 Replies

3. UNIX for Dummies Questions & Answers

What is meant by "LDAP Instances"?

What is meant by "LDAP Instances"?any clarification or examples? (2 Replies)
Discussion started by: ahmedamer12
2 Replies

4. UNIX for Dummies Questions & Answers

What is meant by "exit $?"

What is meant by "exit $?" (4 Replies)
Discussion started by: santosh149
4 Replies

5. Post Here to Contact Site Administrators and Moderators

What is meant by the words under usernames?

Under all users, there are some keynames. Some are obvious, like Moderator and Registered User. I have seen others too. What do they mean or signify?;) (2 Replies)
Discussion started by: joeyg
2 Replies

6. UNIX for Dummies Questions & Answers

What is meant by <<! ... ! ??

I tried typing it into google but no results. I don't know what it's called or what it does and when it is used so I must ask: What does it mean if you have something like... cmd <!! cm2 cm3 ! What do those <!! and ! symbols do? When/why do you use them? I found it inside a bourne... (2 Replies)
Discussion started by: yongho
2 Replies

7. UNIX for Dummies Questions & Answers

What is meant by Kernel Parameter "dflssiz" in Digital Unix (OSF)

Hi, We have a Digital Unix Server with OSF. There's a Kernel Parameter "dflssiz" on this server. I just want to know, what it means. Thanks (2 Replies)
Discussion started by: sameerdes
2 Replies

8. UNIX for Advanced & Expert Users

possibility to call subprocesses from ksh ??

Hi!! Is there a possibility to call/start a subproces using ksh ?? Hope that there is somebody to help me. thanks in advance. Corine (3 Replies)
Discussion started by: TheBlueLady
3 Replies

9. Shell Programming and Scripting

Please help me with this script meant for checking /etc/passwd if a name exists

I'm trying to create a program that includes variety of duties. One of the duties includes deleting a user if the user name exist in the /etc/passwd file. how do i make that happen. those of you that know about this shell programming, please tell me what i should do after the shell reads... (4 Replies)
Discussion started by: TRUEST
4 Replies
Login or Register to Ask a Question