PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] What are the ways to create a new process in C?

 July 22, 2022     c, exec, fork, linux, process     No comments   

Issue

I wonder are there any other ways to create a new process in C. I know about fork which creates a child process. Also, with exec I can replace the current executing program, but yet it does not create a new process.


Solution

As far as I'm aware only fork, vfork and clone are used to create new processes in linux. (posix_spawn is not a syscall, but rather a library function which uses one of the syscalls above to create the process).

exec (and its sibling functions) is used to "mutate" a process, changing its memory layout according to the given ELF file.

(the example below is a very simplified version of the process, that leaves a lot of things out)

For example, when you run a command from your bash terminal, it uses fork (or clone). After the fork syscall, a new process is created and its memory layout is exactly the same as your bash terminal (To understand it better, read about Virtualization & COW, Copy-On-Write). Afterwards, the new process calls execv (or a similar function) to execute the ELF given to it by the command.



Answered By - Amit Sides
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing