Processes Process creation Process memory Function – exec

Transkrypt

Processes Process creation Process memory Function – exec
'
$ '
Jerzy Sobczyk
programm
programm
data 0
• Process creation
• C functions
• Examples
23 lutego 1999 roku
Process memory
process 0
Processes
&
'
$
Jerzy Sobczyk
data 1
process 1
PROCESSES
OS
Jerzy Sobczyk
% &
$ '
1
programm
data 0
data 1
23 lutego 1999 roku
PROCESSES
OS
Jerzy Sobczyk
Function – exec
%
$
3
Process creation
old process
programm
$pid=fork();
if ($pid == 0)
{ ........ child ......... }
elsif ($pid > 0)
{ ........ parent ......... }
else
{ ........ error ......... }
&
23 lutego 1999 roku
PROCESSES
programm
data
OS
% &
2
23 lutego 1999 roku
new process
programm
data
data
PROCESSES
OS
%
4
'
$ '
Jerzy Sobczyk
Signals
signal(SIGQUIT,SIG_DFL);
signal(SIGQUIT,SIG_IGN);
signal(SIGQUIT,proc);
kill(pid,SIGQUIT);
void proc( int sig ) { ... }
&
'
23 lutego 1999 roku
/*
/*
/*
/*
/*
Waiting for a signal
reset to default handling */
ignore signal */
set custom handler */
send signal */
example signal handler */
PROCESSES
OS
Jerzy Sobczyk
23 lutego 1999 roku
int pause(void);
pause() suspends the calling process until it receives a signal. The
signal must be one that is not currently set to be ignored by the
calling process.
% &
$ '
5
23 lutego 1999 roku
PROCESSES
OS
Jerzy Sobczyk
SIGHUP 1 – hangup
SIGINT 2 – interrupt (rubout)
SIGQUIT 3 – quit (ASCII FS)
SIGILL 4 – illegal instruction (not reset when caught)
SIGTRAP 5 – trace trap (not reset when caught)
SIGIOT 6 – IOT instruction
SIGABRT 6 – used by abort, replace SIGIOT in the future
SIGEMT 7 – EMT instruction
SIGFPE 8 – floating point exception
SIGKILL 9 – kill (cannot be caught or ignored)
SIGBUS 10 – bus error
SIGSEGV 11 – segmentation violation
SIGSYS 12 – bad argument to system call
SIGPIPE 13 – write on a pipe with no one to read it
SIGALRM 14 – alarm clock
SIGTERM 15 – software termination signal from kill
SIGUSR1 16 – user defined signal 1
&
$
Jerzy Sobczyk
PROCESSES
%
$
7
Waiting for a child
pid_t waitpid(pid_t pid, int *stat_loc, int options);
pid – ID of the process
stat loc – where to store the exit status
options – options:
WCONTINUED – report also continued processes
WNOHANG – do not suspend execution of the calling process
WNOWAIT – we wish to wait again for the same process
WUNTRACED – report also stopped processes
OS
% &
6
23 lutego 1999 roku
PROCESSES
OS
%
8

Podobne dokumenty