OS Lab4
OS Lab4
Class : %30 I
Student no : 1910205011
Ahmet Yasin Keleş
Question1:
Linux process status : Top command
S -- Process Status
D = uninterruptible sleep
I = idle
R = running
S = sleeping
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.
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 .
touch lab4.cpp
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 )
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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