Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lista 8
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <sys/wait.h>
- int main()
- {
- int potokFd[2];
- pipe(potokFd);
- pid_t childPid=fork();
- if(childPid < 0)
- {
- puts("Nie utworzono procesu potomnego!");
- return -1;
- }
- if(childPid==0)
- {
- close(0); //zamkniecie fd dla wejscia i wyjscia
- close(potokFd[1]);
- dup(potokFd[0]);
- close(potokFd[0]);
- execlp("display", "display", NULL);
- }
- //if(childPid>0)
- //{
- close(potokFd[0]);
- int deskryptor, licznik ;
- char nazwaPliku[100], bufor[128];
- printf("Podaj nazwe pliku: ");
- scanf("%s", nazwaPliku);
- deskryptor = open (nazwaPliku, O_RDONLY);
- while((licznik=read(deskryptor, bufor, 128)) > 0)
- {
- write(potokFd[1], bufor, licznik);
- }
- close(potokFd[1]);
- //}
- wait(NULL);
- return 0;
- }
- Lista 9
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- int main(){
- int potok_fd;
- int deskryptor;
- int licznik;
- char bufor[8];
- char nazwaPliku[100];
- char *FIFO = "../potok";
- mkfifo(FIFO, 0666);
- while(1)
- {
- potok_fd = open(FIFO, O_WRONLY);
- printf("Plik do odczytu: ");
- scanf("%s", nazwaPliku);
- deskryptor = open(nazwaPliku, O_RDONLY);
- while ((licznik=read(deskryptor, bufor, 8)) > 0)
- {
- write(potok_fd, bufor, licznik);
- }
- close(potok_fd);
- }
- return 0;
- }
- Lista 10
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/mman.h>
- int main()
- {
- char nazwaObrazu[100];
- if(fork()==0)
- {
- sleep(4);
- execlp("display", "display", "-update", "1", "obrazek.jpg", NULL);
- }
- while(1)
- {
- printf("Podaj nazwe obrazu: ");
- scanf("%s", nazwaObrazu);
- int fd;
- int fdOdwz;
- fd=open(nazwaObrazu, O_RDWR);
- fdOdwz = open("obrazek.jpg", O_RDWR | O_CREAT, S_IWUSR | S_IRUSR);
- struct stat danePliku;
- fstat(fd, &danePliku);
- truncate("obrazek.jpg", danePliku.st_size);
- char * adrMap;
- adrMap = mmap( NULL , danePliku.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdOdwz, 0 );
- read(fd, adrMap, danePliku.st_size);
- msync( adrMap, danePliku.st_size, MS_SYNC);
- munmap( adrMap, danePliku.st_size);
- close(fd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement