aniketos4
aniketos4
chown
chown <user>:<group> <file> Changes the ownership of a file.
System Calls:
System calls are low-level functions that allow user programs to request services from the OS kernel,
such as file operations, process management, and memory allocation. These run in kernel space and
provide a bridge between the software and hardware. Common system calls include:
System
Call Syntax Description
read ssize_t read(int fd, void *buf, size_t Reads data from a file.
count);
ssize_t write(int fd, const void *buf,
write size_t count); Writes data to a file.
process.
CODES:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h> int
main(void)
{ int val; printf("process id is %d\n",getpid());
printf("the real user id is %d\n",getuid());
printf("the effective user id is %d\n",geteuid());
printf("the effective group id is %d\n",getegid());
if((val=fork())<0)
{
printf("problem in creating process");
return 1; }
if(val==0)
{ printf("process id is %d\n",getpid());
printf("the real user id is %d\n",getuid());
printf("the effective user id is
%d\n",geteuid()); printf("the effective
group id is %d\n",getegid()); }
}
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h> int
main(void)
{ int
n,fd;
char buff[50];
fd=open("test1.txt",O_RDONLY);
printf("the file descriptor for the file is %d\n",fd);
n=read(fd,buff,10); write(1,buff,n);
}
include<stdio.h> #include<unistd.h>
#include<fcntl.h>
int main(int argc,char const *argv[])
{
char name[50],buffer[50];
int fd=open("pb.txt",O_RDWR|O_CREAT);
if(fd!=1) {
printf("enter your name");
fgets(name,50,stdin);
write(fd,name,50);
lseek(fd,0,0); read(fd,buffer,50);
printf("data read from the file is :%s\n",buffer);
close(fd);
} else
{
printf("error!file not open\n");
} close(fd);
return 0;
}
CONCLUSION:
we successfully implement and understand basic Linux commands and system calls related file
management like open(),read() and process management related fork() etc.