xxxxxxxxxx
//Online linux C compiler with working fork
https://rextester.com/l/c_online_compiler_gcc
xxxxxxxxxx
//Another online linux C compiler with working fork/pipe/etc...
https://www.onlinegdb.com/online_c_compiler
xxxxxxxxxx
int main(){
int cpid = fork();
if (cpid == 0){
execl("PATH to SORTING FILE", "SORTING
ARGUMENTS",NULL);
printf("This line will not be printed\n");
}
else{
wait(NULL);
printf("Hello I m Parent.\n");
}
return 0;
}
xxxxxxxxxx
#include <stdio.h>
#include <unistd.h>
int main()
{
int id = fork();
if (id < 0)
printf("Fork failure\n");
else if (id == 0)
printf("Inside child: Pid of Parent Process: %d ::Pid of Child Process: %d\n\n", getppid(), getpid());
else
printf("Inside Parent: Pid of Parent Process: %d ::Pid of Child Process: %d\n\n", getpid(), id);
return 0;
}
xxxxxxxxxx
intmain()
{
inti = 48, pid = -1;
pid = fork();
if (pid == -1)
{
printf ("Fork failed\n");
i++;
exit (1);
}
if (pid == 0)
{
printf ("In child process\n");
printf ("Printing current working directory using execlp system call\n");
i++;
}
else
{
printf ("In parent process\n");
printf ("Name: MAMOONA ASIF\n");
printf ("Roll No: MC180402471\n");
printf ("Program: MIT\n");
i++;
}
}
xxxxxxxxxx
intmain()
{
inti = 48, pid = -1;
pid = fork();
if (pid == -1)
{
printf ("Fork failed\n");
i++;
exit (1);
}
if (pid == 0)
{
printf ("In child process\n");
printf ("Printing current working directory using execlp system call\n");
i++;
}
else
{
printf ("In parent process\n");
printf ("Name: MAMOONA ASIF\n");
printf ("Roll No: MC180402471\n");
printf ("Program: MIT\n");
i++;
}
}
xxxxxxxxxx
#includu<stdio.h>
int fibonacci(int n)
{
if(n==0) return 0;
else if(n==1) return 1;
else return fibonacci(n-1)+fibonacci(n-2);
}
int main()
{
int I,n;
printf("\n enter the limit to generate fibonacci series");
scanf("%d",&n);
for(i=0;i<n;i++)
printf("%3d",fibonacci(i));
return 0;
}
xxxxxxxxxx
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(void){
int i;
uid_t id = geteuid();
struct utsname whoami;
i = uname(&whoami); /* hold the structure */
if ( i == 0 ){
printf("Operating system name : %s\n",whoami.whoami);
}