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
getpid(2)							   System Calls 							 getpid(2)

NAME
getpid, getpgrp, getppid, getpgid - get process, process group, and parent process IDs SYNOPSIS
#include <unistd.h> pid_t getpid(void); pid_t getpgrp(void); pid_t getppid(void); pid_t getpgid(pid_t pid); DESCRIPTION
The getpid() function returns the process ID of the calling process. The getpgrp() function returns the process group ID of the calling process. The getppid() function returns the parent process ID of the calling process. The getpgid() function returns the process group ID of the process whose process ID is equal to pid, or the process group ID of the calling process, if pid is equal to 0. RETURN VALUES
Upon successful completion, these functions return the process group ID. Otherwise, getpgid() returns (pid_t)-1 and sets errno to indicate the error. ERRORS
The getpgid() function will fail if: EPERM The process whose process ID is equal to pid is not in the same session as the calling process, and the implementation does not allow access to the process group ID of that process from the calling process. ESRCH There is no process with a process ID equal to pid. The getpgid() function may fail if: EINVAL The value of the pid argument is invalid. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ SEE ALSO
intro(2), exec(2), fork(2), getsid(2), setpgid(2), setpgrp(2), setsid(2), signal(3C), attributes(5), standards(5) SunOS 5.10 28 Dec 1996 getpid(2)
All times are GMT -4. The time now is 04:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy