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 [Link]
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 [Link] ’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:
[Link]
command-line-in-windows
[Link]
[Link]
%20state%20indicates%20that%20the,suspended%2Fstopped%20from
%20executing%20further.
[Link]
linux
[Link]
tasks
[Link]
[Link]/stop-process?view=powershell-7.2
References of Q2:
[Link]
another-char-string
[Link]
[Link]
in-c
[Link]
functions/strcpy-strncpy/#:~:text=The%20strcpy%20function%20copies
%20string,array%20variable%20or%20directly%20string.
[Link]
4ca473e3d3e1