I am Learning English language
can open the fullPath via OPENDIR(“Full Path ”)
returns DIR* value
then another READDIR(“DIR* ”) return value
biz popkalar ichidagi fayllarni o’qish uchun quyidagi funcsiyalardan foydalanamiz
opendir funksiyasi bilan ochamiz keyin READDIR funksiyasi bilan uni ichidagi file lar nomlarini olamiz.
Programmani ishlatganda kiruvchi va chiquvchi fayllarni berib yuborish uchun quyidagicha amalga oshiriladi :
./a.out < infile > outfile
< bu simvol bilan kiruvchi narsalar ko’rsatiladi.
> bu bilan natijaning chiqish yo’li ko’rsatiladi.
then the file named infile will be copied to the file named outfile.
Figure 1.4. List all the files in a directory
#include
#include
#include
#define BUFFSIZE 4096
int
main(void)
{
int n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n)
err_sys("write error");
if (n < 0)
err_sys("read error");
exit(0);
}
PROCESES
Proceses bilan ishlashda asosan 3 ta yopiq funksiyladan foydalaniladi misol uchun
GETPID() return value =pid_t variable ishlayotgan proces ID ni qaytaradi
Fork() bu funksiya process ID larni birma bir qaytaradi
Exec
waitpid
misol uchun:
#include "apue.h"
#include
int
main(void)
{
char buf[MAXLINE]; /* from apue.h */
pid_t pid;
int status;
printf("%% "); /* print prompt (printf requires %% to print %) */
while (fgets(buf, MAXLINE, stdin) != NULL) {
if (buf[strlen(buf) - 1] == "\n")
buf[strlen(buf) - 1] = 0; /* replace newline with null */
if ((pid = fork()) < 0) {
err_sys("fork error");
} else if (pid == 0) { /* child */
execlp(buf, buf, (char *)0);
err_ret("couldn't execute: %s", buf);
exit(127);
}
/* parent */
if ((pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}
Dostları ilə paylaş: |