01-18-2007
I don't really understand this question. But let's say you have a process running that is a shell. A user has entered the command "date". So no wthe shell would like to run the separate program called "date" and display the results to the user. So the shell will fork and exec the date program. Why? Because that is the only game in town. There is no other way for it to run another program. Either it can fork/exec and thus run the program or it can tell the user "sorry I don't know how to run programs".
10 More Discussions You Might Find Interesting
1. Programming
Hello!
I am working on a server where I should have 4 (resident)processes, one of them being "the father" of the others, so I do 3 forks. The problem that I have is that I do an accept (for sockets) in the "father" process and I want to transmit the job to one of the processes "child" with... (3 Replies)
Discussion started by: driki
3 Replies
2. Programming
On my *nix box, I have a telegram program.
When I go like
tel person "la\nla\nla\n"
the person sees
"la\nla\nla\n"
However, when I have a program that forks and execs tel like:
pid = fork();
if (pid < 0) {
perror("fork failed");
exit(EXIT_FAILURE);
}
if (pid == 0) {... (7 Replies)
Discussion started by: frequency8
7 Replies
3. Solaris
Hi,
I need to find/implement an application that FTPs (puts) all new files in a certain directory to an external storage unit. This application should check for new files every 10 seconds (leaving the FTP connection open in between the 10 seconds).
The easiest way would be if there are... (2 Replies)
Discussion started by: KittyJ
2 Replies
4. Shell Programming and Scripting
I need to ssh to a remote server and run my script there. This is my script.
$ssh = "ssh username@host";
$cmd = "$ssh 'cd <my dir> && < sudo Run_exe>'";
my $pid = fork;
if ($pid == 0){
exec $cmd;
}
When I run this I get:
pccons_getchar: got r == 0 (1 Reply)
Discussion started by: looza
1 Replies
5. Programming
Hello World!
I am writing code in C++ which have to launch another application X using exec().
I would like to set some limits on it using setrlimit etc...
My problem is that i don't know how to forbid using fork() and strlimit by application X.
How can i do it? (3 Replies)
Discussion started by: kzi
3 Replies
6. Programming
Hi All,
In my program i am handling SIGHUP signal. In the handler i fork and then exec on child process same binary file which is running. Parent process will die after 10 mins.
Now my child process which was exec with same binary file is not receiving SIGHUP signal. Below is the progran code:... (6 Replies)
Discussion started by: sushil_shalin
6 Replies
7. Programming
Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine.
So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies
8. UNIX for Dummies Questions & Answers
What is is difference between 'fork with exec' and 'fork without exec'?
How both are related? (1 Reply)
Discussion started by: kkalyan
1 Replies
9. Linux
Hi all,
I am working on a sample backup code, where i read the files per 7200 bytes and send it to server. Before sending to server, i compress each 7200 bytes using zlib compression algorithm using dictionary max length of 1.5 MB . I find zlib is slow.
Can anyone recommend me a... (3 Replies)
Discussion started by: selvarajvss
3 Replies
10. UNIX for Beginners Questions & Answers
Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck
What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies
FORK(2) BSD System Calls Manual FORK(2)
NAME
fork -- create a new process
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <unistd.h>
pid_t
fork(void);
DESCRIPTION
The fork() system call causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent
process) except for the following:
o The child process has a unique process ID.
o The child process has a different parent process ID (i.e., the process ID of the parent process).
o The child process has its own copy of the parent's descriptors. These descriptors reference the same underlying objects, so that,
for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2) on a descriptor in the
child process can affect a subsequent read(2) or write(2) by the parent. This descriptor copying is also used by the shell to
establish standard input and output for newly created processes as well as to set up pipes.
o The child process' resource utilizations are set to 0; see setrlimit(2).
o All interval timers are cleared; see setitimer(2).
o The child process has only one thread, corresponding to the calling thread in the parent process. If the process has more than one
thread, locks and other resources held by the other threads are not released and therefore only async-signal-safe functions (see
sigaction(2)) are guaranteed to work in the child process until a call to execve(2) or a similar function.
RETURN VALUES
Upon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent
process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to
indicate the error.
ERRORS
The fork() system call will fail and no child process will be created if:
[EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded. The limit is given by the
sysctl(3) MIB variable KERN_MAXPROC. (The limit is actually ten less than this except for the super user).
[EAGAIN] The user is not the super user, and the system-imposed limit on the total number of processes under execution by a single
user would be exceeded. The limit is given by the sysctl(3) MIB variable KERN_MAXPROCPERUID.
[EAGAIN] The user is not the super user, and the soft resource limit corresponding to the resource argument RLIMIT_NPROC would be
exceeded (see getrlimit(2)).
[ENOMEM] There is insufficient swap space for the new process.
SEE ALSO
execve(2), rfork(2), setitimer(2), setrlimit(2), sigaction(2), vfork(2), wait(2)
HISTORY
The fork() function appeared in Version 6 AT&T UNIX.
BSD
May 31, 2013 BSD