1753773 Members
5258 Online
108799 Solutions
New Discussion юеВ

System call

 
SOLVED
Go to solution
Karthik S S
Honored Contributor

System call

Hi,

What is the system call invoked when a new process needs to be created??

Thanks
Karthik
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
3 REPLIES 3
Rajeev  Shukla
Honored Contributor
Solution

Re: System call

Hi,

Its fork()
Have a look at the man pages of fork

man fork


Cheers
Rajeev
Michael Tully
Honored Contributor

Re: System call

Hi,

The man page from fork (2) explains everything.
"The fork() system call causes the creation of a new process.

$ man fork

HTH
Michael
Anyone for a Mutiny ?
twang
Honored Contributor

Re: System call

/* ----------------------------------------------------------------- */
/* FUNCTION child: */
/* This function takes 3 arguments(identity, life_time, ground). */
/* It forks a process, sleep for the life_time, the ground is used */
/* to decide whether wait or no wait. */
/* The new child ps shows its detail in both beginning and end time. */
/* ----------------------------------------------------------------- */
void child (char *identity, int life_time, char *ground) {
pid_t pid;
int status;
char buf[50];
time_t t1, t2;
struct tms childtim;

if ((pid = fork()) < 0) {
printf("*** ERROR: %d: forking %s process failed(Life time: %d)\n", getpid(), identity, life_time);
exit(1);
}
else if (pid == 0) { /* for the child process: */
time(&t1);
sprintf(buf, "\n %s process starts\n pid : %d\n ppid : %d\n start_at: %s \n", identity, getpid(), getppid(), asctime(localtime(&t1)));
write(1, buf, strlen(buf));
sleep(life_time);
time(&t2);
times( &childtim );
sprintf(buf, "\n %s process is about to exit\n pid : %d\n CPU_time: %d \n stop_at : %s \n", identity, getpid(), childtim.tms_utime, asctime(localtime(&t2)));
write(1, buf, strlen(buf));
exit(1);
}
else {
if (!strcmp(ground, "f")) {
while (wait(&status) != pid)
;
}
}
}