Sponsored Content
Full Discussion: forking a new process
Top Forums Programming forking a new process Post 302077134 by blowtorch on Monday 19th of June 2006 10:17:59 PM
Old 06-19-2006
Check the man page for fork(2).
Quote:
Originally Posted by man page of fork
The child process inherits the following attributes from the parent
process:

+ Real, effective, and saved user IDs.
+ Real, effective, and saved group IDs.
+ List of supplementary group IDs (see getgroups(2)).
+ Process group ID.
+ Environment.
+ File descriptors.
+ Close-on-exec flags (see exec(2)).
+ Signal handling settings (SIG_DFL, SIG_IGN, address).
+ Signal mask (see sigvector(2)).
+ Profiling on/off status (see profil(2)).
+ Command name in the accounting record (see acct(4)).
+ Nice value (see nice(2)).
+ All attached shared memory segments (see shmop(2)).
+ Current working directory
+ Root directory (see chroot(2)).
+ File mode creation mask (see umask(2)).
+ File size limit (see ulimit(2)).
+ Real-time priority (see rtprio(2)).
It says that the environment does get passed from parent to child. Are you sure that the DISPLAY variable is set in the parent process? Again use getenv to verify that the parent process does indeed have the DISPLAY variable set. If getenv returns NULL, DISPLAY is not set.

Cheers
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Forking

When I compile this C programme I get different outputs each time I run it Please explain to me whats happening in the code if you can give me a detailed explanation with the schedular functionality it will help a lot. Because I am stuck with this. #include <stdio.h> main(){... (3 Replies)
Discussion started by: manjuWicky
3 Replies

2. Programming

forking process.

#include <stdio.h> #include <sys/types.h> #include <unistd.h> int main() { pid_t pID; int i; for (i = 0; i < 3; i++) { pID = fork (); if (pID == 0) { printf ("Value of i --> %d... (2 Replies)
Discussion started by: kymthasneem
2 Replies

3. UNIX for Advanced & Expert Users

VERY confused about forking of child process

hi, I thought that when a child shell is forked, it will inherit all the variables of the parent now in my .cshrc I have setenv X x then I do at command line setenv X y and X is now y. So far so good! I then have a very simple script, y.csh #!/usr/bin/csh echo X (7 Replies)
Discussion started by: JamesByars
7 Replies

4. UNIX for Dummies Questions & Answers

Testing the forking process.

Hey, first time poster and a new UNIX user here. My question is regarding the forking process. I logged in to tty1, and typed the command ls -1 and hit enter. How can i tell that the ls -1 command ran in a subshell? Thanks. (0 Replies)
Discussion started by: Vitamin254
0 Replies

5. Shell Programming and Scripting

Forking with Tclsh vs Wish

Hello, I am new to this site, so sorry ahead of time if this is not the right place for this question.......anywhooooo I am having troubles with forking new processes in wish. Take the following code example: **************************** package require Tclx puts "TCL VER: " proc... (3 Replies)
Discussion started by: pghamami
3 Replies

6. UNIX for Advanced & Expert Users

Forking a new process without parent dependance

hi, I want my program to fork a new process and then I want to kill the parent process. The parent program before dying will issue a SIGTERM to all its childs. Which eventually kills all Children. I cant handle the SIGTERM at the child level.:( What I was thinking of was the Parent... (3 Replies)
Discussion started by: tyler_durden
3 Replies

7. Shell Programming and Scripting

Forking a bunch of processes and filling up the process table

I have a bash script that has been used for months here at work for doing an SSH into other machines both Linux and Solaris and running a script on the remote machine. Recently I have started to noticed that things are being left being on the maching doing the SSH. For example.... tivoli ... (1 Reply)
Discussion started by: LRoberts
1 Replies

8. Programming

Parent forking

My question is, how do you fork only the parent processes in unix? For example how would I use the fork function to fork the parent process more than once and leave the children processes alone. This way I do not have children of children. The way I have it set up now it the parent process forks 3... (7 Replies)
Discussion started by: TWhitt24
7 Replies

9. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

10. Programming

need help in forking

I have an input file with contents like: 5785690|68690|898809 7960789|89709|789789 7669900|87865|659708 7869098|65769|347658 so on.. I need to pass this file to 10 parallely running processes (forking)so that each line is processed by a process and no line is processed twice and write the... (1 Reply)
Discussion started by: rkrish
1 Replies
fork(2)                                                            System Calls                                                            fork(2)

NAME
fork, fork1, forkall - create a new process SYNOPSIS
#include <sys/types.h> #include <unistd.h> pid_t fork(void); pid_t fork1(void); pid_t forkall(void); DESCRIPTION
The fork(), fork1(), and forkall() functions create a new process. The address space of the new process (child process) is an exact copy of the address space of the calling process (parent process). The child process inherits the following attributes from the parent process: o real user ID, real group ID, effective user ID, effective group ID o environment o open file descriptors o close-on-exec flags (see exec(2)) o signal handling settings (that is, SIG_DFL, SIG_IGN, SIG_HOLD, function address) o supplementary group IDs o set-user-ID mode bit o set-group-ID mode bit o profiling on/off status o nice value (see nice(2)) o scheduler class (see priocntl(2)) o all attached shared memory segments (see shmop(2)) o process group ID -- memory mappings (see mmap(2)) o session ID (see exit(2)) o current working directory o root directory o file mode creation mask (see umask(2)) o resource limits (see getrlimit(2)) o controlling terminal o saved user ID and group ID o task ID and project ID o processor bindings (see processor_bind(2)) o processor set bindings (see pset_bind(2)) o process privilege sets (see getppriv(2)) o process flags (see getpflags(2)) o active contract templates (see contract(4)) Scheduling priority and any per-process scheduling parameters that are specific to a given scheduling class might or might not be inherited according to the policy of that particular class (see priocntl(2)). The child process might or might not be in the same process contract as the parent (see process(4)). The child process differs from the parent process in the following ways: o The child process has a unique process ID which does not match any active process group ID. o The child process has a different parent process ID (that is, the process ID of the parent process). o The child process has its own copy of the parent's file descriptors and directory streams. Each of the child's file descriptors shares a common file pointer with the corresponding file descriptor of the parent. o Each shared memory segment remains attached and the value of shm_nattach is incremented by 1. o All semadj values are cleared (see semop(2)). o Process locks, text locks, data locks, and other memory locks are not inherited by the child (see plock(3C) and memcntl(2)). o The child process's tms structure is cleared: tms_utime, stime, cutime, and cstime are set to 0 (see times(2)). o The child processes resource utilizations are set to 0; see getrlimit(2). The it_value and it_interval values for the ITIMER_REAL timer are reset to 0; see getitimer(2). o The set of signals pending for the child process is initialized to the empty set. o Timers created by timer_create(3RT) are not inherited by the child process. o No asynchronous input or asynchronous output operations are inherited by the child. o Any preferred hardware address tranlsation sizes (see memcntl(2)) are inherited by the child. o The child process holds no contracts (see contract(4)). Record locks set by the parent process are not inherited by the child process (see fcntl(2)). Although any open door descriptors in the parent are shared by the child, only the parent will receive a door invocation from clients even if the door descriptor is open in the child. If a descriptor is closed in the parent, attempts to operate on the door descriptor will fail even if it is still open in the child. Threads A call to forkall() replicates in the child process all of the threads (see thr_create(3C) and pthread_create(3C)) in the parent process. A call to fork1() replicates only the calling thread in the child process. In Solaris 10, a call to fork() is identical to a call to fork1(); only the calling thread is replicated in the child process. This is the POSIX-specified behavior for fork(). In previous releases of Solaris, the behavior of fork() depended on whether or not the application was linked with the POSIX threads library. When linked with -lthread (Solaris Threads) but not linked with -lpthread (POSIX Threads), fork() was the same as forkall(). When linked with -lpthread, whether or not also linked with -lthread, fork() was the same as fork1(). In Solaris 10, neither -lthread nor -lpthread is required for multithreaded applications. The standard C library provides all threading support for both sets of application programming interfaces. Applications that require replicate-all fork semantics must call forkall(). fork() Safety If a multithreaded application calls fork() or fork1(), and the child does more than simply call one of the exec(2) functions, there is a possibility of deadlock occurring in the child. The application should use pthread_atfork(3C) to ensure safety with respect to this dead- lock. Should there be any outstanding mutexes throughout the process, the application should call pthread_atfork() to wait for and acquire those mutexes prior to calling fork() or fork1(). See "MT-Level of Libraries" on the attributes(5) manual page. RETURN VALUES
Upon successful completion, fork(), fork1(), and forkall() return 0 to the child process and return the process ID of the child process to the parent process. Otherwise, (pid_t)-1 is returned to the parent process, no child process is created, and errno is set to indicate the error. ERRORS
The fork(), fork1(), and forkall()function will fail if: EAGAIN A resource control or limit on the total number of processes, tasks or LWPs under execution by a single user, task, project, or zone has been exceeded, or the total amount of system memory available is temporarily insufficient to duplicate this process. ENOMEM There is not enough swap space. EPERM The {PRIV_PROC_FORK} privilege is not asserted in the effective set of the calling process. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |fork() is Standard. fork1() | | |and forkall() are Stable. | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe. | +-----------------------------+-----------------------------+ SEE ALSO
alarm(2), exec(2), exit(2), fcntl(2), getitimer(2), getrlimit(2), memcntl(2), mmap(2), nice(2), priocntl(2), semop(2), shmop(2), times(2), umask(2), door_create(3DOOR), exit(3C), plock(3C), pthread_atfork(3C), pthread_create(3C), signal(3C), system(3C), thr_create(3C) timer_create(3RT), wait(3C), contract(4), process(4)attributes(5), privileges(5), standards(5) NOTES
An applications should call _exit() rather than exit(3C) if it cannot execve(), since exit() will flush and close standard I/O channels and thereby corrupt the parent process's standard I/O data structures. Using exit(3C) will flush buffered data twice. See exit(2). The thread in the child that calls fork() or fork1() must not depend on any resources held by threads that no longer exist in the child. In particular, locks held by these threads will not be released. In a multithreaded process, forkall() in one thread can cause blocking system calls to be interrupted and return with an EINTR error. SunOS 5.10 19 Jul 2004 fork(2)
All times are GMT -4. The time now is 03:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy