0% found this document useful (0 votes)
6 views6 pages

Lab Task Submission for Zoha Irfan

The document contains source code for 7 questions on operating systems concepts like printing output, using loops, taking user input, fork(), and demonstrating parent-child processes and process IDs.

Uploaded by

dicor68383
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Lab Task Submission for Zoha Irfan

The document contains source code for 7 questions on operating systems concepts like printing output, using loops, taking user input, fork(), and demonstrating parent-child processes and process IDs.

Uploaded by

dicor68383
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Shaheed Zulfikar Ali Bhutto Institute of Science &

Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

Total Marks:

Obtained Marks:

Operating System
(LAB)
Class Task #03

Submitted To: Madam Zoha Irfan


_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Student Name: Abdul Hadi


______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Reg. Number: 21108124


______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

AI BSAI-5A SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

Q1: Print hello world.


Source Code:
# include <stdio.h>

int main()
{
print("Hello World");
return 0;
}

Q2: Print hello world.


Source Code:
#include<stdio.h>

void main() {

int i; //Variable definition

printf("The first 10 natural numbers are:\n ");

for (i = 1; i <= 10; i++) //Iteration 10 times


{
printf("%d \t", i); //Print the number.
}
}

Q3: take two numbers from user and print their sum

AI BSAI-5A SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

Source Code:
#include <stdio.h>
int main() {

int number1, number2, sum;

printf("Enter two integers: ");


scanf("%d %d", &number1, &number2);

// calculate the sum


sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);


return 0;
}

Question 4:
Source Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
fork();

printf("Hellow World!\n");
return 0;
}

Question 5:
Source Code:
#include <stdio.h>
#include <sys/types.h>
int main()
{

AI BSAI-5A SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

fork();
fork();
fork();
printf("hello\n");
return 0;
}

Question 6:
Source Code:
#include <stdio.h>
#include <sys/types.h>

int main()
{
int id;
id = fork();
printf("idvalue: %d\n", id);
if(id == 0)
{

printf("Child: hello i am the child process\n");


printf("Child: Child's PID: %d\n", getpid());
printf("Child: Parent's PID: %d\n", getppid());
}
else
{
printf("Parent: hello i am the parent process\n");
printf("Parent: Parent's PID: %d\n", getpid());
printf("Parent: Child's PID: %d\n", id);
}

AI BSAI-5A SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

Question 7:
Source Code:
#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
printf("Parent has x = %d\n", --x);
}

int main()
{
forkexample();
return 0;
}

AI BSAI-5A SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology

ARTIFICIAL INTELLIGENCE DEPARTMENT

AI BSAI-5A SZABIST-ISB

You might also like