# echo przykład przykład. echo przykład



Podobne dokumenty
1. Utwórz blok pamięci współdzielonej korzystając z poniższego kodu:

# echo przykład przykład. echo przykład

1. Uruchom poniższy program tworzący pojedynczy wątek:

Systemy operacyjne II Skrypt do ćwiczeń laboratoryjnych

w odróżnieniu od procesów współdzielą przestrzeń adresową mogą komunikować się za pomocą zmiennych globalnych

Systemy operacyjne II

Shared memory and messages. Functions. process 0. process 1. program 0. program 0. data 0. data 1. program 1. data 0. data 1.

Obsługa plików Procesy

Łącza nienazwane(potoki) Łącza nienazwane mogą być używane tylko pomiędzy procesami ze sobą powiązanymi.

4.2 Sposób korzystania z l acza

Obsługa plików. Systemy Operacyjne 2 laboratorium. Mateusz Hołenko. 25 września 2011

Procesy. Systemy Operacyjne 2 laboratorium. Mateusz Hołenko. 9 października 2011

POSIX: IEEE Std (Issue 6, 2004 edition)

Semafory, pamięć dzielona i kolejki komunikatów

Programowanie Współbieżne

Łącza nienazwane(potoki)

SYSTEMY OPERACYJNE I laboratorium 3 (Informatyka stacjonarne 2 rok, semestr zimowy)

Procesy. S. Samolej: Procesy

Poniższe funkcje opisane są w 2 i 3 części pomocy systemowej.

procesy odrębne dzielone

Temat zajęć: Tworzenie i obsługa wątków.

Sygnały. 7. Sygnały (2005/2006)

Pobieranie argumentów wiersza polecenia

KOLEJKI KOMUNIKATÓW IPC

J. Ułasiewicz Programowanie aplikacji współbieżnych 1

Temat zajęć: Obsługa procesów w systemie.

J. Ułasiewicz Łącza nienazwane, nazwane, select 1

Instytut Teleinformatyki

Procesy, pliki, potoki, sygnały - uzupełnienie

Krótki kurs programowania współbieżnego

Jądro Powłoka System plików Programy użytkowe

2. Zarządzanie procesami

4. Komunikacja pomiędzy procesami przez łącza nienazwane i nazwane

Funkcje jadra systemu operacyjnego UNIX

Programowanie w ANSI C z wykorzystaniem funkcji jądra systemu UNIX/Linux

Laboratorium Systemów Operacyjnych. Ćwiczenie 4. Operacje na plikach

Problem producentakonsumenta

Wstęp do informatyki. stęp do informatyki Polecenia (cz.2)

sposób wykonywania operacji zapisu i odczytu dane odczytywane z l acza usuwane (nie można ich odczytać ponownie),

Pliki. Funkcje tworzące pliki i operujące na nich opisane są w części 2 pomocy systemowej. Tworzenie i otwieranie plików:

Programowanie aplikacji równoległych i rozproszonych. Wykład 1

Funkcje jadra systemu operacyjnego UNIX

Procesy w systemach UNIX i Linux

Plan wykładu. Programowanie aplikacji równoległych i rozproszonych. Wykład 1 p. Wzajemne wykluczanie. Procesy współbieżne

J. Ułasiewicz Łącza nienazwane, nazwane, select 1

Programowanie Współbieżne. Komunikacja między procesowa IPC

Jędrzej Ułasiewicz Programownie aplikacji współbieżnych str. 1. Wątki

Pamięć współdzielona

Temat zajęć: Obsługa łączy komunikacyjnych

UŻYCIE I ZARZĄDZANIE WĄTKAMI

Model procesu w systemie Linux. Tomasz Borzyszkowski

Funkcje zawarte w bibliotece < io.h >

UŻYCIE I ZARZĄDZANIE WĄTKAMI

Procesy i potoki. S. Samolej: Procesy

Programowanie Współbieżne. W Linuxie/Unixie

Informatyka. Wy-03 Dynamiczna alokacja pamięci, wyjątki. mgr inż. Krzysztof Kołodziejczyk

PROGRAMOWANIE SYSTEMÓW CZASU RZECZYWISTEGO

Krótki kurs programowania współbieżnego (2)

Programowanie Proceduralne

Funkcje zawarte w bibliotece < io.h >

Unix: programowanie z użyciem w atków

Unix: programowanie z użyciem w atków

Programowanie równoległe w POSIX API. PRiR, wykład 3

Temat zajęć: Obsługa systemu plików.

Mariusz Rudnicki PROGRAMOWANIE SYSTEMÓW CZASU RZECZYWISTEGO CZ.4

Problemy współbieżności

Podstawy programowania współbieżnego. 1. Wprowadzenie. 2. Podstawowe pojęcia

SUMA KONTROLNA (icmp_cksum) NUMER KOLEJNY (icmp_seq)

2. Zarządzanie procesami

Mariusz Rudnicki PROGRAMOWANIE WSPÓŁBIEŻNE I SYSTEMY CZASU RZECZYWISTEGO CZ.4

Wątki. S. Samolej: Wątki 1

Tworzenie wątków. #include <pthread.h> pthread_t thread;

Mechanizmy z grupy IPC

Uzupełnienie dot. przekazywania argumentów

Dariusz Wawrzyniak 11 maja 2001

Dariusz Wawrzyniak 5 kwietnia 2001

UNIX - KOLOKWIUM 3. #include <stdio.h> #include <unistd.h>

Plan wykładu. Obliczenia równoległe w zagadnieniach inżynierskich. Wykład 1 p. Wzajemne wykluczanie. Procesy współbieżne

Bash - wprowadzenie. Bash - wprowadzenie 1/39

Języki i metodyka programowania. Typy, operatory, wyrażenia. Wejście i wyjście.

Politechnika Gdańska Wydział Elektrotechniki i Automatyki Katedra Inżynierii Systemów Sterowania

5. Algorytmy serwera

<stdio.h> <iostram> input. FILE *stdin. std::cin output. std::cout error. FILE *stdout. FILE *stderr

1. Procesy i współbieżność

IPC: Kolejki komunikatów

Wstęp do Programowania, laboratorium 02

Mechanizmy z grupy IPC

Informacje o procesach czyli polecenie "ps".

Wykład 15. Literatura. Kompilatory. Elementarne różnice. Preprocesor. Słowa kluczowe

pami eć operacyjna przechowuje dane do przetworzenia, tymczasowe dane pomocnicze,

3 Przygotował: mgr inż. Maciej Lasota

Temat zajęć: Mechanizmy IPC: kolejki komunikatów.

Podstawy informatyki. Informatyka stosowana - studia niestacjonarne. Grzegorz Smyk. Wydział Inżynierii Metali i Informatyki Przemysłowej

ZAJECIA Z SYSTEMÓW OPERACYJNYCH 2 (Programowanie): funkcje POSIX

Laboratorium z systemów operacyjnych. System plików - funkcje systemowe. Anna Wojak

dynamiczny przydział pamięci calloc() memset() memcpy( ) (wskaźniki!! )

Kolejki FIFO (łącza nazwane)

Operacje powiązane z systemem:

Gniazda BSD. komunikacja bezpołączeniowa

Struktury. Przykład W8_1

Transkrypt:

# # echo przykład przykład echo przykład

fg jobs # sleep 10 # <Ctrl-Z> # ls... # jobs [1]+ Stopped sleep 10 # fg,,,,, #include <stdio.h> int main() printf( Hello world!\n ); vi mcedit pico jed emacs

# cc -o hello hello.c #./hello Hello world! # cc -Wall -o hello hello.c hello.c: In function main : hello.c:6: warning: control reaches end of non-void function int main() return 0; -Wall printf(3) # man 3 printf # export LANG=pl_PL.UTF-8 # man 2 open aplikacja funkcje biblioteczne funkcje systemowe (jądro systemu) write printf printf printf write

man # man 2 open # man 3 printf printf main() int char** int main(int argc, char* argv[]) int i; for(i=0; i<argc; i++) printf( argument %d: %s\n, i, argv[i]);

open open O_RDONLY O_WRONLY O_RDWR O_CREAT open fd = open( przyklad.txt, O_WRONLY O_CREAT, 0644); open stdin stdout stderr przykład.txt open

close(fd); close write(fd, Czesc, 5); write char buf[20];... n = read(fd, buf, 20); read write read read while((n=read(fd, buf, 20)) > 0) write(1, buf, n); errno int perror errno fd = open( przyklad.txt, O_RDONLY); if (fd == -1) printf( Kod: %d\n, errno); perror( Otwarcie pliku ); exit(1); errno errno.h

setlocale(lc_all, pl_pl.utf-8 ); fd = open( przyklad.txt, O_WRONLY O_APPEND O_CREAT, 0644); fd = unlink( przyklad.txt ); ftruncate fd = open( przyklad.txt, O_WRONLY); ftruncate(fd, 0); # umask 022 # umask 077 umask lseek int lseek(int fd, int offset, int whence); offset whence SEEK_SET SEEK_CUR SEEK_END lseek(fd, -1, SEEK_END); cat # mycat a.txt b.txt c.txt cp tee # ps ax mytee wynik.log wc

toupper # cat plik.txt tr a-z A-Z cmp lseek flock int fd = open(...); flock(fd, LOCK_EX);... flock(fd, LOCK_UN); LOCK_EX LOCK_SH fcntl struct flock lck; int fd = open(...); lck.l_type = F_WRLCK; lck.l_start = 10; lck.l_len = 20; lck.l_whence = SEEK_SET; fcntl(fd, F_SETLKW, &lck);... lck.l_type = F_UNLCK; fcntl(fd, F_SETLKW, &lck); F_WRLCK l_type F_RDLCK #./baza dane.db w 5 1234 A test dane.db

#./baza dane.db r 5 1234 A test hexdump # hexdump -C dane.db

printf( Poczatek\n ); fork(); printf( Koniec\n ); sleep fork ps -l #./a.out & # ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 R 1011 2567 2566 0 75 0-1233 - pts/2 00:00:00 bash 0 S 1011 2589 2567 0 75 0-337 schedu pts/2 00:00:00 a.out 0 S 1011 2590 2589 0 75 0-337 schedu pts/2 00:00:00 a.out 1 R 1011 2591 2567 0 75 0-905 - pts/2 00:00:00 ps fork getpid getppid int x; x = fork(); printf( wynik fork=%d PID=%d PPID=%d\n, x, getpid(), getppid()); fork(); fork(); if (fork()==0) fork();

printf( Poczatek\n ); execl( /bin/ls, ls, -l, NULL); printf( Koniec\n ); ls -l printf( Poczatek\n ); if (fork()==0) /* proces potomny */ execlp( ls, ls, -l, NULL); exit(1); printf( Koniec\n ); if (fork()==0) /* proces potomny */... else /* proces macierzysty */ wait(null); printf( Koniec\n ); if (fork()==0) /* proces potomny */ exit(5); else /* proces macierzysty */ int stat; wait(&stat); printf( status=%d\n, stat>>8); sleep exec execvp execvp sort -n -k 3,3 -t: /etc/passwd

ps ax out.txt int fd; close(1); fd = open( out.txt, O_WRONLY O_CREAT, 0644); execlp( ps, ps, ax, NULL); dup dup2 int fd; fd = open( out.txt, O_WRONLY O_CREAT, 0644); dup2(fd, 1); # ls -l -a -i >> wynik.txt # grep xy < dane.txt > wynik1.txt 2> wynik2.txt

#include <stdio.h> #include <signal.h> void obsluga(int signo) printf( Odebrano sygnał %d\n, signo); int main() signal(sigint, obsluga); while(1) ; #./a.out C Odebrano sygnał 2 \ Quit kill #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> void obsluga(int signo)

printf( Odebrano sygnał %d\n, signo); exit(0); int main() int pid; if ((pid=fork())==0) signal(sigint, obsluga); while(1); sleep(2); printf( Wysyłam sygnał do procesu potomnego %d\n, pid); kill(pid, 2); return 0; alarm pause pause printf( Naciśnij Ctrl-C\n ); pause(); printf( Dziękuję!\n ); sleep int x = 0;... while(x==0) ; x # cc -O2 czekaj.c -o czekaj #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> #include <sys/wait.h>

void obsluga(int signo) int s; wait(&s); printf( Status zakończenia procesu potomnego: %d\n, s>>8); int main() signal(sigchld, obsluga); if (fork()==0) sleep(3); exit(5); while(1) sleep(1); printf( Proces macierzysty\n ); waitpid

pipe #include <stdio.h> #include <unistd.h> int main() int fd[2]; char buf[100]; pipe(fd); write(fd[1], Hello, 6); read(fd[0], buf, 6); printf( %s\n, buf); return 0; pipe(fd); if (fork()==0) write(...); exit(0);... sleep ls tr a-z A-Z #include <stdio.h>

#include <unistd.h> int main() int fd[2]; pipe(fd); if (fork()==0) dup2(fd[1], 1); execlp( ls, ls, NULL); else dup2(fd[0], 0); execlp( tr, tr, a-z, A-Z, NULL); return 0; out.txt # ls tr a-z A-Z > out.txt # ls -l /tmp sort -n -k 5,5 tail -5 # hostname -f #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int main() int fd; mkfifo( fifo, 0600); fd = open( fifo, O_WRONLY); write(fd, Hello, 6); close(fd); return 0;

ps ax tr a-z A-Z socketpair int fd[2]; if ((socketpair(pf_unix, SOCK_STREAM, 0, fd))==-1) perror( socketpair ); exit(1);

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/shm.h> int main() int id; id = shmget(0x111, 1024, 0600 IPC_CREAT); if (id==-1) perror( shmget ); exit(1); printf( Blok utworzony: %d\n, id); return 0; ipcs # ipcs ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000111 3342338 sobaniec 700 1024 0 ------ Semaphore Arrays -------- key semid owner perms nsems ------ Message Queues -------- key msqid owner perms used-bytes messages ipcrm # ipcrm -M 0x111

# ipcrm -m 3342338 char* ptr;... ptr = shmat(id, NULL, 0); strcpy(ptr, Ala ma kota ); char* ptr;... shmdt(ptr); id = shmget(0x111, 1024, 0);... shmctl(id, IPC_RMID, NULL);

#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/shm.h> #include <string.h> void obsluga(int sig) printf( sygnał w procesie %d\n, getpid()); int main() int id; char *ptr; int pid; signal(sighup, obsluga); id = shmget(0x111, 1024, 0600 IPC_CREAT); if (id==-1) perror( shmget ); exit(1); ptr = (char*)shmat(id, NULL, 0); if ((pid=fork())==0) int ppid = getppid(); sleep(1); while(1) strcpy(ptr, xxxxxx ); sleep(1); kill(ppid, 1); pause(); strcpy(ptr, oooooo ); sleep(1); kill(ppid, 1); pause(); else while(1) pause(); printf( %s\n, ptr); sleep(1); kill(pid, 1);

#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/shm.h> #include <string.h> int ok = 0; void obsluga(int sig) ok = 1; int main() int id; char *ptr; int pid; signal(sighup, obsluga); id = shmget(0x111, 1024, 0600 IPC_CREAT); if (id==-1) perror( shmget ); exit(1); ptr = (char*)shmat(id, NULL, 0); if ((pid=fork())==0) int ppid = getppid(); while(1) strcpy(ptr, xxxxxx ); ok = 0; kill(ppid, 1); while(!ok); strcpy(ptr, oooooo ); ok = 0; kill(ppid, 1); while(!ok); else while(1) while(!ok); printf( %s\n, ptr); ok = 0; kill(pid, 1);

#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/shm.h> #include <string.h> void obsluga(int sig) int main() int id; char *ptr; int pid; sigset_t mask, mask_old; signal(sighup, obsluga); sigemptyset(&mask); sigaddset(&mask, SIGHUP); sigprocmask(sig_block, &mask, &mask_old); id = shmget(0x111, 1024, 0600 IPC_CREAT); if (id==-1) perror( shmget ); exit(1); ptr = (char*)shmat(id, NULL, 0); if ((pid=fork())==0) int ppid = getppid(); while(1) strcpy(ptr, xxxxxx ); kill(ppid, 1); sigsuspend(&mask_old); strcpy(ptr, oooooo ); kill(ppid, 1); sigsuspend(&mask_old); else while(1) sigsuspend(&mask_old); printf( %s\n, ptr); kill(pid, 1);

#include <stdio.h> #include <stdlib.h> #include <sys/sem.h> int main() int sid; struct sembuf op; sid = semget(0x123, 1, 0600 IPC_CREAT); if (sid == -1) perror( semget ); exit(1); op.sem_num = 0; op.sem_flg = 0; /* podniesienie semafora (+1) */ op.sem_op = 1; semop(sid, &op, 1); /* opuszczenie semafora (-1) */ op.sem_op = -1; semop(sid, &op, 1); return 0; ipcs # ipcs ------ Shared Memory Segments --------

key shmid owner perms bytes nattch status ------ Semaphore Arrays -------- key semid owner perms nsems 0x00000123 32768 sobaniec 700 1 ------ Message Queues -------- key msqid owner perms used-bytes messages ipcrm # ipcrm -S 0x123 # ipcrm -s 32768 int num;... num = semctl(sid, 0, GETVAL, 0); printf( semaphore value: %d\n, num); num = 1; semctl(sid, 0, SETVAL, num); #include <stdio.h> #include <stdlib.h> #include <sys/sem.h> int main(int argc, char* argv[]) int sid; struct sembuf op; sid = semget(0x123, 1, 0600 IPC_CREAT); if (sid == -1) perror( semget ); exit(1); printf( przed: %d\n, semctl(sid, 0, GETVAL, NULL)); op.sem_num = 0; op.sem_flg = 0; op.sem_op = atoi(argv[1]); semop(sid, &op, 1); printf( po: %d\n, semctl(sid, 0, GETVAL, NULL)); return 0; #include <stdio.h>

#include <stdlib.h> #include <unistd.h> #include <sys/sem.h> int main(int argc, char* argv[]) int sid; int num; struct sembuf op; sid = semget(0x123, 1, 0600 IPC_CREAT); if (sid == -1) perror( semget ); exit(1); if (argc>1) printf( Inicjacja semafora...\n\n ); num = 1; semctl(sid, 0, SETVAL, num); op.sem_num = 0; op.sem_flg = 0; while(1) printf( Wchodzę do sekcji krytycznej...\n ); op.sem_op = -1; semop(sid, &op, 1); printf( Jestem w sekcji krytycznej...\n ); sleep(5); op.sem_op = 1; semop(sid, &op, 1); printf( Wyszedłem z sekcji krytycznej...\n ); sleep(1); return 0;

msgget(2) mid = msgget(0x123, 0600 IPC_CREAT); ipcs long typedef struct long type; char text[1024]; MSG; msgsnd(2) MSG msg;... msgsnd(mid, &msg, strlen(msg.text)+1, 0); ipcs msgrcv(2) MSG msg;... msgrcv(mid, &msg, 1024, 0, 0); msgrcv long

msgrcv msgctl msgctl(mid, IPC_RMID, NULL); ipcrm

#include <stdio.h> #include <unistd.h> #include <pthread.h> void* worker(void* info) int i; for(i=0; i<10; i++) sleep(1); printf( thread\n ); return NULL; int main() pthread_t th; int i; pthread_create(&th, NULL, worker, NULL); for(i=0; i<10; i++) sleep(1); printf( main program\n ); pthread_join(th, NULL); return 0; # cc -o thtest thtest.c -lpthread # ps x # ps -L x

# ps -T x int d = 1; pthread_create(&th, NULL, worker, &d); #include <stdio.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mx; void* worker(void* info) int i; int tid = *(int*)info; for(i=0; i<10; i++) printf( Thread %d is entering critical section...\n, tid); pthread_mutex_lock(&mx); printf( Thread %d is in critical section...\n, tid); sleep(5); pthread_mutex_unlock(&mx); printf( Thread %d is leaving critical section...\n, tid); sleep(2); return NULL; int main() pthread_t th1, th2, th3; int w1=1, w2=2, w3=3; pthread_mutex_init(&mx, NULL); pthread_create(&th1, NULL, worker, &w1); pthread_create(&th2, NULL, worker, &w2); pthread_create(&th3, NULL, worker, &w3); pthread_join(th1, NULL); pthread_join(th2, NULL); pthread_join(th3, NULL); return 0; pthread_join(3)

int pthread_join(pthread_t th, void **retval); wait retval void pthread_exit(void *retval); retval pthread_join pthread_cancel int pthread_cancel(pthread_t thread); int pthread_setcancelstate(int state, int *oldstate); int pthread_detach(pthread_t th); pthread_join signal int pthread_kill(pthread_t thread, int signo); int pthread_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask); newmask unsigned long int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigaddset(sigset_t *set, int signum); int sigdelset(sigset_t *set, int signum); int sigismember(const sigset_t *set, int signum); pthread_sigmask int sigwait(const sigset_t *set, int *sig);

int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr); pthread_mutex_t m;... pthread_mutex_init(&m, NULL); pthread_mutex_lock() pthread_mutex_trylock() EBUSY pthread_mutex_unlock() pthread_mutex_destroy() pthread_mutex_t int pthread_cond_t c;... pthread_cond_init(&c, NULL); int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond); pthread_cond_signal() pthread_cond_broadcast() int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);

int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); pthread_cond_wait() pthread_cond_timedwait() pthread_cond_t c; pthread_mutex_t m;... pthread_mutex_lock(&m); /* zajęcie zamka */ pthread_cond_wait(&c, &m); /* oczekiwanie na zmiennej warunkowej */ pthread_mutex_unlock(&m); /* zwolnienie zamka */ pthread_cond_signal(&c); /* sygnalizacja zmiennej warunkowej */ pthread_mutex_lock(&m); pthread_cond_signal(&c); pthread_mutex_unlock(&m); sem_init() sem_init() sem_wait() sem_trywait() sem_post() sem_getvalue()

sem_destroy() int pthread_cond_signal() pthread_cond_broadcast() bariera()

#include <stdio.h> #include <unistd.h> #include <pthread.h> #include <semaphore.h> sem_t s; void* work(void* arg) int id = pthread_self(); int i; for(i=0; i<10; i++) printf( [%d] Czekam...\n, id); sem_wait(&s); printf( [%d] Sekcja krytyczna...\n, id); sleep(1); printf( [%d] Wyjście...\n, id); sem_post(&s); usleep(100000); return NULL; int main() pthread_t th1, th2; sem_init(&s, 0, 1); pthread_create(&th1, NULL, work, NULL); pthread_create(&th2, NULL, work, NULL); pthread_join(th1, NULL); pthread_join(th2, NULL); return 0;

# cc -o prg modul_1.c modul_2.c prg.c modul_.c modul_.c prg.c main # cc -c modul_1.c # cc -c modul_2.c # cc -o prg modul_1.o modul_2.o prg.c.o.a tar modul_.c modul_.c # cc -c modul_1.c # cc -c modul_2.c # ar rv libmodul.a modul_1.o modul_2.o # cc -o prg prg.c libmodul.a

# cc -shared -o libmodul.so modul_1.c modul_2.c # cc -o prg prg.c -lmodul -L. -L modul ldd # ldd prg linux-gate.so.1 => (0xffffe000) libc.so.6 => /lib/libc.so.6 (0x40027000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) modul.so =>./modul.so (0x40027000) #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> int main() void* handle = dlopen( libhello.so, RTLD_LAZY); void (*fun)(); if (handle == NULL) printf( %s\n, dlerror()); exit(1); else fun = dlsym(handle, fun ); (*fun)(); dlclose(handle); return 0; #include <stdio.h> void fun() printf( Hello world\n ); dlopen(3)

rand(3) RAND_MAX srand(3) [, ] float f = rand()/(rand_max+1.0); x int x; srand(getpid()); x = 1 + 10.0*(rand()/(RAND_MAX+1.0)); getpid #include <stdio.h> #include <readline/readline.h> int main() char* line; while ((line=readline( pisz> ))!=NULL) if (*line)

printf( %s\n, line); # gcc -o readline-test -lreadline readline-test.c line = readline( > ); add_history(line);

# ls -l > out.txt # grep abc < dane.txt # sort < dane.txt > out.txt exit fg bg jobs isatty() #!/home/student/mysh ls -l ps ax > out.txt

# ps ax head # ps ax head # ls -l tr a-z A-Z sort -n -k 5,5 # cat < dane.txt tr abc XYZ sort > out.txt echo $1 $2 #!/home/student/mysh ls -l $1 tr -s \t cut -f $2 > X=10 > echo $X 10 > zmienna= Ala ma kota > echo $zmienna Ala ma kota > unset zmienna > echo $zmienna > setenv() = proces.txt

proces.txt ps -ax iostat netstat -tn log.txt numbers.txt

gcc cc -Wall error: x undeclared (first use in this function) x warning: implicit declaration of function sleep sleep sleep sleep(3) unistd.h #include <unistd.h> warning: no newline at end of file mcedit

add_history dlopen exec perror printf pthread_join rand readline sleep srand toupper alarm close dup2 dup fcntl flock fork ftruncate getpid getppid lseek msgget msgrcv msgsnd open pause pipe read signal socketpair umask waitpid write