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

OS Lab4

The document provides information about process status in Linux and Windows operating systems. In Linux, the top command shows process status which can be D, I, R, S, T, t, or Z. In Windows, PowerShell or Task Manager do not show process status directly but threads can have states of 0-7. When a parent process is killed in Linux, child processes are also killed, but in Windows child processes continue running. Additionally, Linux top command provides more process information than commands in Windows. The second question provides C++ code to kill a process by ID entered by the user on Linux. It uses system(), sprintf(), strncpy(), strcat() functions.

Uploaded by

hakiki
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)
92 views6 pages

OS Lab4

The document provides information about process status in Linux and Windows operating systems. In Linux, the top command shows process status which can be D, I, R, S, T, t, or Z. In Windows, PowerShell or Task Manager do not show process status directly but threads can have states of 0-7. When a parent process is killed in Linux, child processes are also killed, but in Windows child processes continue running. Additionally, Linux top command provides more process information than commands in Windows. The second question provides C++ code to kill a process by ID entered by the user on Linux. It uses system(), sprintf(), strncpy(), strcat() functions.

Uploaded by

hakiki
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
You are on page 1/ 6

OS LAB WEEK 4 H.W.

Class : %30 I
Student no : 1910205011
Ahmet Yasin Keleş

Question1:
Linux process status : Top command

S -- Process Status

The status of the task which can be one of:

D = uninterruptible sleep

I = idle

R = running

S = sleeping

T = stopped by job control signal

t = stopped by debugger during trace

Z = zombie
Windows Process status : PowerShell (ps or Get-Process) or Task manager
Thread States:
0 - Initialized. It is recognized by the microkernel.
1 - Ready. It is prepared to run on the next available processor.
2 - Running. It is executing.
3 - Standby. It is about to run. Only one thread may be in this state at a time.
4 - Terminated. It is finished executing.
5 - Waiting. It is not ready for the processor. When ready, it will be rescheduled.
6 - Transition. The thread is waiting for resources other than the processor.
7 - Unknown. The thread state is unknown.
Compare :
1- When you kill a mother process in linux you kill child process too.

But in Windows child process continues to running .

2- In linux you just type top in terminal and that command show almost everthing , In
windows you cant see status in PowerShell or cmd .You need to script to see status of
process. (i tried Get-Process , tasklist, wmic process list commands and none of them show
status)

Question2:
Note : this program only works in linux .

First create a cpp file

touch lab4.cpp

Then write program

CODE :
#include <stdio.h>
#include <stdlib.h>
int main(){
char pid[20]= "kill -9 1594" ; // kill command with pid
system(pid);
return 0;
}
and type in terminal ’ g++ -o lab4 lab4.cpp ’code and compile the file . (Check SS1 )

C codes : Extra Point Challenge

(i also add cpp file and SS )

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[])


{

char const * kill_command = "kill -9 "


char comm[50], pid [sizeof(int)*8+1],check[1] ;
int x = 8;
int i;

printf ("Enter a pid: ");

if (scanf ("%d",&i) == 1) { // pid input from user

sprintf(pid, "%d",i); // int to string


printf ("PID : %s\n",pid); // check pid
strncpy(comm, kill_command, x);
comm[x] = '\0'; // without that show error idk !
strcat(comm, pid);
strcat(comm, kill_command + x);

printf("press 'y' to kill process \n");


scanf("%1s",check);

if (check[0]=='y')
{
system(comm); // kill process
}else{
exit(0);
}

References of Q1:
https://superuser.com/questions/914782/how-do-you-list-all-processes-on-the-
command-line-in-windows

https://www.geeksforgeeks.org/top-command-in-linux-with-examples/

https://devm.io/programming/linux-process-states-173858#:~:text=STOPPED
%20state%20indicates%20that%20the,suspended%2Fstopped%20from
%20executing%20further.

https://www.tutorialspoint.com/what-are-the-process-states-in-windows-and-
linux

https://stackoverflow.com/questions/46546587/powershell-get-all-suspended-
tasks

https://learn.microsoft.com/en-us/powershell/module/
microsoft.powershell.management/stop-process?view=powershell-7.2

References of Q2:

https://stackoverflow.com/questions/2015901/inserting-char-string-into-
another-char-string

https://www.tutorialspoint.com/c_standard_library/c_function_system.htm

https://stackoverflow.com/questions/8257714/how-to-convert-an-int-to-string-
in-c

http://www.trytoprogram.com/c-programming/c-string-handling-library-
functions/strcpy-strncpy/#:~:text=The%20strcpy%20function%20copies
%20string,array%20variable%20or%20directly%20string.

https://berviantoleo.medium.com/safe-way-to-handle-user-input-in-c-
4ca473e3d3e1

You might also like