On 07Feb2008 13:23, sajid_mirani <[EMAIL PROTECTED]> wrote:
| how can we use a fork function  ? can you gave a simple example of this 
| function ?

  pid_t = fork();
  if (pid < 0)
    /* fork() failed - report error and cancel actions */
  else if (pid == 0)
    /* we are the new child process - getpid() can
     * be used to find out our own process id
     */
  else
    /* we are the original, parent process
     * pid == what getpid() in the child would tell the child
     */

Normal "run a program" approach would look a little bit like this:

  pid_t pid = fork();
  if (pid == 0)
    /* child */
    execvp(... the new executable and arguments ...)
  else if (pid > 0)
    /* parent */
    wait();     /* wait for the child to exit */

This is greatly simplified. A real program will do much more than this,
with proper error checking and handling. See the manual entries for
details.

| After the fork function, if we change the values of some 
| global variables in the child function, then the values of the 
| variables changed in the parent function or not ?
| in the same way if we change values in parent funtion then it will 
| change in child or not ?

"Not", in both cases.
-- 
Cameron Simpson <[EMAIL PROTECTED]> DoD#743
http://www.cskk.ezoshosting.com/cs/

There are only two types of ships in the NAVY; SUBMARINES and TARGETS !!!
        - Richard Pierson


To unsubscribe from this list, please email [EMAIL PROTECTED] & you will be 
removed. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/LINUX_Newbies/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/LINUX_Newbies/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to