Thread: CreateProcess

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Question CreateProcess

    Hi,
    Is there something like windows CreateProcess in linux?
    The only way to start a process in my program is to use system(); ?
    Oh, do not answer to this question please

    Any answer is appreciated

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You might want to look into fork.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Thanks, But As I understood fork() creates a child process with the same memory address.
    But I want to start another bin or executable file!!! Run another program?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    system()
    exec()
    popen()

    all launch executables.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Yes, But as I know all of this functions invoke a shell to do that?!!!!
    Any system call?!

  6. #6

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by hosseinyounesi View Post
    Yes, But as I know all of this functions invoke a shell to do that?!!!!
    Any system call?!
    There is no system call without the shell. Indeed, as I mentioned early:
    the bash shell is derived from an older unix power tool called "the C shell", and many "system commands" are actually part of the shell -- they do not have their own executables.
    That includes stuff like cd. The shell manages process for init, the parent of all processes.
    Last edited by MK27; 07-26-2009 at 07:03 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Cool

    thanks, I got it now

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    Quote Originally Posted by hosseinyounesi View Post
    Yes, But as I know all of this functions invoke a shell to do that?!!!!
    Any system call?!
    No, the exec family of functions doesn't invoke a shell.

  10. #10
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    That includes stuff like cd. The shell manages process for init, the parent of all processes.
    Um, what? My init is /sbin/init, and my shell is /bin/bash -- they are two very separate processes/programs.

    To add a bit here -- CreateProcess is the equivalent of a fork() then an exec() of some sort. *nix gives more flexibility in process creation than Windows does.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  11. #11
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Lightbulb

    this can be a way. But the forked process name is not the executed application name!!! It's name is the process name that calls fork? Am I right? How to fix this?

    Thanks anyone

  12. #12

  13. #13
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    CreateProcess is the equivalent of a fork() then an exec() of some sort. *nix gives more flexibility in process creation than Windows does.
    You are right. Another question: If a child process terminate before the parent, after a few time the parent will be a "Zombie" process. And we know that "exec(newProcess)" family system calls, replace (so the child will terminate) the current process with newProcess.
    If I use a fork and If I use exec in child process, the parent will not be a Zombie process! Why?
    Thanks in advance

  14. #14
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    man waitpid:

    Quote Originally Posted by man waitpid
    WAIT(2) Linux Programmer's Manual WAIT(2)

    NAME
    wait, waitpid, waitid - wait for process to change state

    SYNOPSIS
    #include <sys/types.h>
    #include <sys/wait.h>

    pid_t wait(int *status);

    pid_t waitpid(pid_t pid, int *status, int options);

    int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);

    Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

    waitid(): _SVID_SOURCE || _XOPEN_SOURCE

    DESCRIPTION
    All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the
    child whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal; or the
    child was resumed by a signal. In the case of a terminated child, performing a wait allows the system to release the resources
    associated with the child; if a wait is not performed, then the terminated child remains in a "zombie" state (see NOTES below).

    If a child has already changed state, then these calls return immediately. Otherwise they block until either a child changes state
    or a signal handler interrupts the call (assuming that system calls are not automatically restarted using the SA_RESTART flag of
    sigaction(2)). In the remainder of this page, a child whose state has changed and which has not yet been waited upon by one of
    these system calls is termed waitable.

    wait() and waitpid()
    The wait() system call suspends execution of the calling process until one of its children terminates. The call wait(&status) is
    equivalent to:

    waitpid(-1, &status, 0);

  15. #15
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Thanks, But my question is: When I use fork and the exec in child process, the parent will not be "zombie" although the child is terminated. WHY ?

    (As you know, If a child terminates before parent, the parent will be "zombie")

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateProcess() + Command Line
    By IndioDoido in forum Windows Programming
    Replies: 20
    Last Post: 11-14-2008, 07:35 PM
  2. CreateProcess with arguments
    By Niara in forum Windows Programming
    Replies: 14
    Last Post: 09-08-2007, 05:41 AM
  3. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 01:07 AM
  4. question on CreateProcess() redirection
    By ac251404 in forum Windows Programming
    Replies: 13
    Last Post: 07-18-2006, 11:06 AM
  5. CreateProcess
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 05-12-2002, 06:45 AM

Tags for this Thread