Well, It’s my first blog, and thus I’ll try to show a small view through Processes on Linux. I hope we can to be happy here quite, unless you’re not a Linux user ahahaaa.
We can now begin to look at the interface between the operating system and application programm, that is, the set of system calls. Although, this discussion specifically refers to POSIX(International Standard 9945-1) , hence is to Linux as well.
To make the system call that leads with processes on Linux, let’s to take a quick look at FORK syscall. (obs: Throughout this commit I’ll use to syscall term either “syscall” or “system call”.)
FORK is only a way to create a new process. It creates exact duplicate of the original process. Including all the file descriptors, registers-everything. After FORK, the original process and the copy(the parent and child) go their separate ways. All these variables identical values at the time of the FORK, but since the paraten’s data are copied to create the child, though, subsequent changes in one of them do not affect the other one. (The text shared, which is unchangeable, is shared between parent and child). The fork call returns a value, which is zero in the child, and equal to the child’s process identifier or pid(Process Identifier) in the parent.
You can see an example below, whose it shows how to make a process under Linux:
#include <unistd.h>
int main()
{
while(1) { /* repeat forever */
read(command, parameters); /* read command of the terminal */
if(fork() != 0) { /* fork off child process */
/* parent code */
waitpid(-1, &status, 0); /* wait for a child to exit */
} else {
/* child code */
execve(command, parameters, 0); /* execute command */
}
return 0;
}
obs: WAITPID can wait for a specific child, or for any old child by setting the first parameter as “-1″ will be set to the child’s exist status.
I’d like to suggest you, a great book to lead about this overview like “MINIX system calls”, however, Linux and MINIX are POSIX, the book would be: “Operating Systems: Design and Implementation”.
Happy, Hacking.
Regards,
Paulo