6.프로세스와 시그널

6-1 프로세서란 무엇인가?

6-2 sytem

#include <stdlib.h>

int system(const char *string)

int main()

{

printf("Running ps with system \n");

system("ps -ax");

printf("done.\n");

exit(0)

}

6-3 exec

#include <unistd.h>

int execl(const char *path, const char *arg0...0);

int execlp(const char *file, const char *arg0..0);

int execle(const char *path,const char *arg0,....,0,char *envp[]);

int execvp(const char *path ,const char *argv[]);

int execve(const char *path, const char *argv[],char *envp[]);

#include <unistd.h>

#include <stdio.h>

int main()

{

printf("Running ps with execlp\n");

execlp("ps","ps","-ax",0);

exit(0);

}

6-4 fork

#include <sys/types.h>

#include <unistd.h>

#include <stdio.h>

int main()

{

pid_t pid;

char *message;

int n;

printf("fork program starting\n");

pid=fork();

switch(pid)

{

case -1:

printf("fork failed);

exit(1);

case 0:

message="child";

n=5;

break;

default:

message="this is the parent";

n=3;

break;

}

}

for(;n>0;n--)

{

puts(message);

sleep(1);

}

exit(0);

}

추가부분

if(pid !=0)

{

int stat_val;

pid_t child_pid;

child_pid= wait(&stat_val);

printf("Child has finished: PID=%d\n",child_pid);

}