Fork syscall and related issues


 
Thread Tools Search this Thread
Top Forums Programming Fork syscall and related issues
# 1  
Old 11-06-2009
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

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

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

5. appications that uses sockets

6. 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:

Code:
#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));
     }
}


Smilie
# 2  
Old 11-06-2009
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.
5. Sendmail, Postfix, Firefox, FTP, SSH, ... pretty much anything using a network.
6. 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.
# 3  
Old 02-19-2010
some info

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
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Network related issues

Oflate we are finding a few servers experiencing severe slowness. What would be the commands that I need to try to postmortem the situation? (3 Replies)
Discussion started by: ggayathri
3 Replies

2. Programming

Download file with socket syscall

Hello to all I want download a file in osx intel 64 with NASM , I want to use socket syscall This is part of my code section .data command db "GET /test/2.gif HTTP/1.1\r\nHost: 10.1.1.187\r\n\r\n", 0 ; url db "http://172.16.207.153/test/2.gif", 0 global main... (1 Reply)
Discussion started by: recher.jack
1 Replies

3. Red Hat

Adding our system call Fedora 18 -new syscall

Hi, I wanna add my own system call to Fedora 18 kernel 3.8.2. From kernel 3.3 I heard there is a new system to add system calls. So where i can find a guides ? I wanna print this text: "Hello world!" in terminal, not dmesg. (4 Replies)
Discussion started by: googz
4 Replies

4. Solaris

Swap space related issues, how to recognise the newly attached disk

hi!:) i got a problem....:wall::wall: i got several disks in my diskarray. I attached new disk to allocate it to the swap space. The problem is : how to recognise the newly attached disk? I've one more requirement -:wall:- i want to run dns service on another port number.how can i do... (2 Replies)
Discussion started by: vamshigvk475
2 Replies

5. UNIX for Advanced & Expert Users

Process on CPU inside syscall

Hello Experts, If a Solaris process is calling some syscall, and right now execution is inside syscall doing only CPU work, for example the inside simplest times syscall, -> app_func => times << we are here now, we have entered in the times, but not exited yet <= times <- app_func... (9 Replies)
Discussion started by: sant
9 Replies

6. UNIX for Dummies Questions & Answers

is read() syscall really a primitive?

I saw somewhere that describe read() as a primitive. But when I lean signals, it says the read() may be interrupted by a signal. My Question: 1, What is the diffence between primitive and reentrant? 2, Is read() a primitive or reentrant? 3, Are all system calls primitive or reentrant? (2 Replies)
Discussion started by: vistastar
2 Replies

7. UNIX for Advanced & Expert Users

how to distinguish entry/exit of a syscall when using ptrace?

Hi all, I am using ptrace to keep track of clone syscalls in a program. However, I found that the traced syscall cant be paired. for example, there are some syscalls that have entry, but without exit showing up in the traced sequences. So, is there anyway to distinguish the entry and exit of a... (0 Replies)
Discussion started by: tristartom
0 Replies

8. Programming

recv syscall for socket programming

I have a question regarding the recv syscall. Suppose I have a client/server and the following exchange of message took place: Client --> Server using multiple send syscalls one after another immediately: send "Packet1" send "Packet2" send "Packet3" Server receives in the... (2 Replies)
Discussion started by: heljy
2 Replies
Login or Register to Ask a Question