spawn() Vs. fork()


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users spawn() Vs. fork()
# 1  
Old 03-11-2012
Bug spawn() Vs. fork()

what is diffenrence between spawn and fork ?

"fork() system call spawns the processess" what is mean by this sentence.
# 2  
Old 03-11-2012
When UNIX creates a new process, for example when you login:

1. the kernel has to take an existing process and then copy all of it into another part of memory.

2. Next it creates kernel entries to support the new process.

3. Finally it gives control of the cpu to user space in the new process

4. (optional) load an executable image into the process overwriting the old process memory. exec() does this, fork() does not do this.

Steps 1-3 is what fork() does, it is commonly called spawning a new process. Step 4 is performed by exec(). They are very different. So when you type
Code:
awk '{print $3}' somefile

You create a child process using 1,2, 3, then you exec() awk, step 4.

Where the problems come in:

1. all modern UNIX systems also support posix_spawn(), which does not copy all of memory. Its function is to do a "lightweight" version of fork().

2. Linux has something like posix_spawn() called clone().

3. Some other oddball systems also have a spawn() system call which acts more or less like fork()/exec().

An example of fork()/exec() is the C system() function.

So in effect you can say:
fork() spawns a new process.
posix_spawn() spawns a new process.
clone() spawns a new process.
system() spawns a new process.

So, the word spawn does not have to refer to a specific UNIX function, just what happens to make a new process.
These 2 Users Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spawn command not found!!!

Hi, I am writing a script to automate installation of java in shell script. #!/bin/sh #!/usr/bin/expect ls -la | grep jdk* | rpm -ivh ./jdk*.rpm alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/java 2 spawn alternatives --config java expect "Enter to keep the current... (5 Replies)
Discussion started by: boby.kumar
5 Replies

2. Red Hat

Spawn: command not found

Dear Concern, I want to run following script in RHEL 6.3. $ cat sftp_upload.sh #!/usr/bin/expect spawn sftp -oPort=434 bkashtopup@172.16.252.59 expect "*?assword:*" send "bkashtopup1234\n" send "lcd /BI/application/report/script/daily/daily_bkash_itopup_detail\r" expect sftp> ... (3 Replies)
Discussion started by: makauser
3 Replies

3. Red Hat

Spawn: Command not found

Hi all, I want to run the following command from my main prompt : # spawn bash but I get the following error: spawn: Command not found. For this to work , I first have to go into expect. #expect expect1.1>spawn bash spawn bash 564 expect1.2> Is there any way I can skip the... (2 Replies)
Discussion started by: Junaid Subhani
2 Replies

4. Shell Programming and Scripting

Sleep 600 or fork/spawn a process or daemon?

Hi, I have a script that run every 10 minutes, from a specific timeframe of the day, for example 0500 - 1900. The script is some sort of checker script for an application log file and check for errors and email us if there is error/s reported in the log. At the moment, I schedule it... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. Shell Programming and Scripting

Help with spawn.. newbie to shell

Hi, I have a problem with the spawn execution with expect.. i have done the code for expect in a separate file and i am calling the this execution from the bash script.. as given below.. -bash-4.1$ cat main.sh #!/usr/bin/bash ./spawn.exp ========================== -bash-4.1$ cat... (2 Replies)
Discussion started by: satishkumar432
2 Replies

6. Shell Programming and Scripting

Spawn snmptrap from python

Hi I am trying to spawn an snmptrap from python but i keep getting the following error Invalid version specified after -v flag: 2c -c public 192.168.2.162 SNMPv2-SMI::enterprises.3.1.1 here is the python code i am using from subprocess import Popen Popen() When i test the same... (0 Replies)
Discussion started by: kaf3773
0 Replies

7. Shell Programming and Scripting

Using spawn and expect getting error

#!/bin/sh # # set -x stty -echo; read -p "Input password:" A; stty echo; echo; for HOST in `cat elc.hosts.list` do # echo "Connecting to $HOST" expect -c "set timeout -1;\ spawn sshr $HOST -l root \"mkdir /perfstat;\";\ match_max 100000;\ expect *'/root/.ssh/id_dsa':*;\ send --... (1 Reply)
Discussion started by: madlot
1 Replies

8. Programming

spawn a process with a different user

Hello Everyone: I have the following code int main() { system("/usr/OtherUser/bin/runX"); return 0; } runX must be executed with privileges from another user, how could I do that? I know the password for such user. Thanks in advance (8 Replies)
Discussion started by: edgarvm
8 Replies

9. Solaris

Spawn Not Found

I need to run the spawn command but when I typed it in, I got "ksh: spawn: not found". So, I downloaded spawn-fcgi but it required to be compiled first. The compile failed when I tried it. I need a copy that's ready to be used. Unix system info: OS: Sun Solaris 2.8 Shell: ksh Does... (4 Replies)
Discussion started by: april
4 Replies

10. UNIX for Dummies Questions & Answers

spawn: not found

Hi, I'm very new to UNIX. I need to FTP a file to a remote host. It happens through a port 2222.I need to automate the process as the SCP command prompts for a password. 1) The regular ftp, tells me that the connection is refused 2) The sftp login@remotehost gives me... (0 Replies)
Discussion started by: sandy.cog
0 Replies
Login or Register to Ask a Question