.


:




:

































 

 

 

 





Linux , . , , , .. , , , .

man. man , , :

man gdb

gdb. man- . q.

, . , time shell, . man . man- . , (). , time : time(1). , man , :

man 1 time

, , , .

Linux :

 

  ,
  ,
  libc, , qsort(3)
  , /dev
  /etc/passwd
   
  "" , , ASCII , .
  mount(8), root
  . , Linux , , , .

 

 

 

. , , , , , ..

. .. , , , .

, , . (pid), .

Linux Windows.

 

Linux

Linux fork(). -. - , fork(). fork() -, - 0; -1.

:

pid = fork();

switch(pid) {

-1: ; //

0: ; //

default: ; //

}

. exec. (execv, execve, execl ..) , . exec- , , .

Unix fork() exec -. , fork(), .

:

1) , p (execvp execlp), . .

2) v (execv, execve execvp) null- . l (execl, execle execlp) , C.

3) e (execve execle) , . null- , VARIABLE=value.

(main) exit().

getpid(). getppid().

wait() waitpid(). , wait(), init, Unix. , - - , .. -. - , .. . , , . , .

 

Windows

Windows CreateProcess(). :

pszApplicationName , ;

pszCommandLine , ;

psaProcess ;

psaThread ;

bInheritHandles ;

fdwCreate , ;

pvEnvironment , ;

pszCurDir ;

psiStartupInfo . CreateProcess(), . cb .

ppiProcInfo PROCESS_INFORMATION, .

:

;

ExitProcess();

TerminateProcess();

.

Windows -. . WaitForSingleObject() WaitForMultipleObjects().

 

: Linux Windows. , . , . Linux ncurses.

 

2

: .

 

, , , . , (race condition) , . , . , , , .

, (, ). . .

, . :

;

, . ;

;

.

Linux, Windows . .

 

Linux

 

Linux .

 

. - . . , . , .

, , . :

int sig_int(); /* - */

...

signal(SIGINT, sig_int); /* */

...

sig_int()

{

signal(SIGINT, sig_int); /* */

... /* ... */

}

 

, , - signal. , SIGINT .

:

#include <signal.h>

void (*signal(int signo, void (*func)(int)))(int);

signal ( SIGINT, SIGUSR1 ..) -, int ( ) . signal . signal SIG_IGN ( ) SIG_DFL ( ).

, , . , , , .. .. .

:

 

#include <signal.h>

int sigaction(int signo, const struct sigaction *restrict act, struct sigaction *restrict oact);

, . act NULL, . oact NULL, . signo signal.

sigaction -1, 0.

sigaction:

 

struct sigaction {

void (*sa_handler)(int);

sigset_t sa_mask;

int sa_flags;

void (*sa_sigaction)(int, siginfo_t *, void *);

};

 

:

sa_handler -. SIG_IGN SIG_DFL;

sa_mask , , - . ;

sa_flags , . 0;

sa_sigaction . , SA_SIGINFO.

 

: kill() raise(). , , .. . :

 

#include <signal.h>

int kill(pid_t pid, int signo);

int raise(int signo);

 

pid , , signo .

 

- , . , (IPC, Inter Process Communication).

, . , (semaphore set).

:

 

#include <sys/sem.h>

int semget(key_t key, int nsems, int flag);

 

:

key , . (long int) ftok();

nsems ;

flag , .

 

1 . (flag IPC_CREAT), . key, , nsems 0.

: semop() semctl().

semop() :

 

#include <sys/sem.h>

int semop(int semid, struct sembuf semoparray[], size_t nops);

 

semid , ; semoparray sembuf, ( , ); nops ( ).

 

sembuf:

struct sembuf {

unsigned short sem_num;

short sem_op;

short sem_flg;

};

 

sem_num , ( ), s em_op . :

sem_op > 0: ;

sem_op = 0: . , ;

sem_op < 0: , . , , .. sem_op.

, sem_flg IPC_NOWAIT, , semop() -1 errno EAGAIN.

, :

, ;

, .

 

semctl() , , , .. semop(), semctl() , . , .

 

Windows

 

Windows .

 

Windows . unix-, , : . : .

CreateEvent():

HANDLE CreateEvent(PSECURITY_ATTRIBUTES psa, BOOL fManualReset, BOOL fInitialState, PCTSTR pszName);

:

psa ;

fManualReset TRUE, , FALSE ;

fInitialState (TRUE , FALSE - );

pszName - .

 

:

CreateEvent() , ;

;

DuplicateHandle();

OpenEvent() .

 

: SetEvent() , ResetEvent() . WaitForSingleObject(). , .

 

Windows . Unix Windows . .

Windows CreateSemaphore():

 

HANDLE CreateSemaphore(PSECURITY_ATTRIBUTE psa, LONG lInitialCount, LONG lMaximumCount, PCTRTR pszName);

:

psa ;

fManualReset TRUE, , FALSE ;

lInitialCount ;

lMaxCount ;

pszName - .

 

, Linux, Windows , . , . OpenSemaphore().

ReleaseSemaphore() . 1, , .

( ) WaitForSingleObject(), WaitForMultipleObjects(), MsgWaitForMultipleObjects(). .

 

: Linux Windows. . , . + , - , q . . , .. , . /.

 

 

3

 

: .

 

. : , . , , , .. , .

 

Linux

 

Linux (pipes) .

 

, . , . Unix- , .. ; . , .

pipe():

#include <unistd.h>

int pipe(int filedes[2]);

filedes , , .

, pipe() 0. 1.

read() write(), FILE* fdopen(). -, fprintf() fgets().

, , . fork() -.

, . , - ( ).

 





:


: 2016-03-28; !; : 447 |


:

:

, .
==> ...

1670 - | 1527 -


© 2015-2024 lektsii.org - -

: 0.099 .