LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create and Call a Process (https://www.linuxquestions.org/questions/linux-newbie-8/create-and-call-a-process-834207/)

mailkamlesh 09-24-2010 05:30 AM

Create and Call a Process
 
Hi All

I had an interview , where the interviewer asked me the question
"How to create and call a process in unix"


I answered that we can use the command
FORK()/ CLONE() to create a process.

But I didnt have the answer for the second question, how to call a process.

Can someone help me with the second question ?

Thanks

TheIndependentAquarius 09-24-2010 05:45 AM

Quote:

Originally Posted by mailkamlesh (Post 4107530)
how to call a process.

Process is just a program in execution.

e.g. The set of lines written in the ls file is a program and when we type ls on the prompt, it gets called and thus the ls becomes a process which we called !!

and also you can use special system calls to call a program e.g. system (), execvp () and popen () etc.

IMHO

prayag_pjs 09-24-2010 06:56 AM

System call is the services provided by Linux kernel. In C programming, it often uses functions defined in libc
which provides a wrapper for many system calls.

It is also possible to invoke syscall() function directly. Each system call has a function number defined in
<syscall.h> or <unistd.h>. Internally, system call is invokded by software interrupt 0x80 to transfer control to
the kernel. System call table is defined in Linux kernel source file “arch/i386/kernel/entry.S ”

System Call Example
#include <syscall.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
int main(void) {
long ID1, ID2;
/*-----------------------------*/
/* direct system call */
/* SYS_getpid (func no. is 20) */
/*-----------------------------*/
ID1 = syscall(SYS_getpid);
printf ("syscall(SYS_getpid)=%ld\n", ID1);
/*-----------------------------*/
/* "libc" wrapped system call */
/* SYS_getpid (Func No. is 20) */
/*-----------------------------*/
ID2 = getpid();
printf ("getpid()=%ld\n", ID2);
return(0);
}


All times are GMT -5. The time now is 07:51 PM.