Professional Documents
Culture Documents
Abhishek Kandel(19BCE2629)
#include<stdio.h>
int main(void)
printf("hello world\n");
fork( );
fork( );
Output:
#include<stdio.h>
int main(void)
int pid;
printf("hello world\n");
pid=fork();
if (pid==0){
else{
Output:
#include <stdio.h>
#include <sys/types.h>
int main()
fork();
fork();
fork();
printf("hello\n");
return 0;
Output:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
int main()
forkexample();
return 0;
Output:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void forkexample()
int x = 1;
if (fork() == 0)
printf("Child has x = %d\n", ++x);
else
int main()
forkexample();
return 0;
Output:
#include<stdio.h>
#include<unistd.h>
main(void){
printf("before forking\n");
fork();
fork();
Output:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
#include <pthread.h>
sleep(1);
return NULL;
int main()
pthread_t thread_id;
printf("Before Thread\n");
pthread_join(thread_id, NULL);
printf("After Thread\n");
exit(0);
Output:
Write a C program to kill a process by specifying its name rather than its PID.
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <error.h>
#include <signal.h>
#include <unistd.h>
#include <syslog.h>
int main()
FILE *getPIDS;
char line[130];
pid_t killpid;
kill(line,SIGKILL);
}
Output:
THANK YOU!!!