Sponsored Content
Top Forums Programming Fork syscall and related issues Post 302368919 by MrUser on Friday 6th of November 2009 01:48:59 AM
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
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

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

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

8. 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
PCNTL_FORK(3)								 1							     PCNTL_FORK(3)

pcntl_fork - Forks the currently running process

SYNOPSIS
int pcntl_fork (void ) DESCRIPTION
The pcntl_fork(3) function creates a child process that differs from the parent process only in its PID and PPID. Please see your system's fork(2) man page for specific details as to how fork works on your system. RETURN VALUES
On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised. EXAMPLES
Example #1 pcntl_fork(3) example <?php $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { // we are the parent pcntl_wait($status); //Protect against Zombie children } else { // we are the child } ?> SEE ALSO
pcntl_waitpid(3), pcntl_signal(3), setproctitle(3). PHP Documentation Group PCNTL_FORK(3)
All times are GMT -4. The time now is 03:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy