Fork syscall and related issues

Hi all,
i just started started learning system programming and want to pursue a career in the sys prog area.
below is the program that use a fork() call.
i read in one of the tutorials that parent process and child process uses different address spaces and runs concurrently.
that meas each process gets some slice of cpu time, then the statements in that process are executed.
my Questions:
1.is there any way to know how much timeslice each process is getting.

2.what kind of scheduling its using

  1. can i print the out put one page at a time ( should wait for keypress to print next page)

  2. any links that provides good system programming info(message queues, pipes,shared memory etc.. )

  3. appications that uses sockets

  4. fork returns zero to the child process and some +ve value to parent.
    how is it able to return two values.

below is some example prog:

#include  <stdio.h>
#include  <sys/types.h>
#define   MAX_COUNT  200
void  ChildProcess(pid_t);                /* child process prototype  */
void  ParentProcess(pid_t);               /* parent process prototype */
void  main(void)
{
     pid_t  pid;
     pid = fork();
     if (pid == 0) 
          ChildProcess(pid);
     else 
          ParentProcess(pid);
}
void  ChildProcess(pid_t pid)
{
     int   i;
     char buf[40];
     for(i=1; i <= MAX_COUNT; i++) {
          sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
          write(1, buf, strlen(buf));
     }
}
void  ParentProcess(pid_t pid)
{
     int   i;    
     char buf[40];
     for(i=1; i <= MAX_COUNT; i++) {
          sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
          write(1, buf, strlen(buf));
     }
}

:confused:

  1. No
  2. Depends on what scheduler the kernel uses.
  3. Yes, but this has nothing to do with system or concurrent programming, but with counting how much output you already produced and waiting after a certain amount.
  4. Sendmail, Postfix, Firefox, FTP, SSH, ... pretty much anything using a network.
  5. It doesn't. By the time fork() finishes, there are already 2 separate processes. In the parent process it's returning the PID of the child. In the child it returns 0. If it can't spawn a child for any reason, it returns -1 and sets errno.

Who have asked few number of questions , I will explain few things about the fork and its usage.

fork is simply creating a process from some other process. The environment, resource limits, umask, controlling terminal, current working directory, root directory, signal masks and other process resources are also duplicated from the parent in the forked child process.

The reason for returning the two values is that we can easily differentiate the process and do appropriate in particular process.

Also another system call available named vfork().If you use that then the parent and the child will use the same address space.

When we use fork then the wait is also comes into that.It is used to make the parent to wait till the child get terminate.

But when we speak about sockets it is better to use select system call instead of forking new process.Because forking processes continuously will make the efficiency down.

Read man pages of fork,vfork,wait,waitpid.

The GNU C Library - Child Processes

Fork, Exec and Process control