The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remote Exec TheEngineer AIX 1 05-12-2006 04:50 AM
find and exec big123456 UNIX for Advanced & Expert Users 2 01-02-2006 12:10 PM
exec comand mkan UNIX for Dummies Questions & Answers 5 09-09-2005 03:24 AM
using the -exec command moxxx68 UNIX for Dummies Questions & Answers 0 04-13-2004 02:51 PM
exec Nisha Shell Programming and Scripting 1 09-23-2002 05:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-30-2007
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
exec

I have read that exec "replaces the current process with a new one".

So I did

$ exec ls

and after this executed, my shell disappeared. I am assuming that my shell had PID xyz, and when I did exec ls, this ls got pid xyz, and when it terminated, there was no more shell process running, and so it terminated. Is this correct??

Second question, say I am running a Java program, and I do a system call, of exec ls. Does this mean that the Java process will be replaced by ls?

Thanks in advance.
  #2 (permalink)  
Old 12-30-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,951
for exec ls,

the child process ls - will replace the address space of the parent process which is the interpretor, after exec effectively there is only one address space in execution previously it was the parent ( shell ) and now its the child ( ls )

After execution of ls, like any other binary - ls also terminates. Once it terminates the session also closes as there is no effective program running
  #3 (permalink)  
Old 12-30-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
As the adverts says: "It does exactly what it says on the tin."
  #4 (permalink)  
Old 12-30-2007
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
oh, I get it. The parent is replaced by the child. Yes, makse sense.

Thanks.
  #5 (permalink)  
Old 12-30-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by JamesByars View Post
oh, I get it. The parent is replaced by the child. Yes, makse sense.

Thanks.
Almost, there is no child process created.

In UNIX a process is a running entity managed by the operating system and a program is a file on disk.

In MS-DOS, Windows, OS/2, classic MacOS the only way to create a process was to run a program and the OS would create a new process to run the program.

In UNIX they are two separate activities (a) create a new process, ie, fork and (b) replace the current running program with a new program, eg exec.

So in Windows what would be "CreateProcess" is in UNIX a fork followed by exec. Although 99% of the time we want to fork/exec there are a few occasions where replacing the current program is the thing to do.
  #6 (permalink)  
Old 12-30-2007
JamesByars JamesByars is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 124
Ah. I get it (this time I do!!!)

Thanks!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0