I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V()
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <sys/stat.h>
void printStat(char *filename);
//Main
int main(int argc, char *argv[])
{
//Process Id (storing)
pid_t pid;
int j;
//printf("Welcome to Project Three\n”);
// For loop*/
for (j = 1; j < argc; j++)
{
//forking process
pid=fork();
//Child process (if condition)
if (pid == 0)
{
printStat(argv[j]);
return 0;
}
else{
}
}
//Waiting for the child to finish
while( wait(NULL) > 0 );
//Printing the current running process
system("ps -H");
printf("The End!\n");
exit(0);
}
////////////Biginning of lab 3////////////////////////
void printStat(char *filename)
{
//struct
struct stat sb;
printf("File: %s\n", filename);
//if condition
if (stat(filename, &sb) == -1)
{
printf("error in stat \n");
exit(1);
}
//if condition to see if the current user is the file's owner
if((sb.st_uid == getuid())&&(sb.st_gid == getgid()))
{
printf("You Have Owner Permissions: ");
if(sb.st_mode & S_IRUSR)
printf("Read ");
if(sb.st_mode & S_IWUSR)
printf("Write ");
if(sb.st_mode & S_IXUSR)
printf("Execute ");
}
//check if the file's Group is same current user's Group
else if ((sb.st_uid != getuid())&&(sb.st_gid == getgid()))
{
printf("You Have Group Permissions: ");
if(sb.st_mode & S_IRGRP)
printf("Read ");
if(sb.st_mode & S_IWGRP)
printf("Write ");
if(sb.st_mode & S_IXGRP)
printf("Execute ");
}
else
{
printf("You Have Other Permissions: ");
if(sb.st_mode & S_IROTH)
printf("Read ");
if(sb.st_mode & S_IWOTH)
printf("Write ");
if(sb.st_mode & S_IXOTH)
printf("Execute ");
}
printf("\n");
}//End Lab 3
#include <stdio.h>
#include <sched.h>
#include <errno.h>
#include <sched.h>
#include <stdio.h>
#include "test.h"
#include "usctest.h"
struct test_case_t {
int policy;
} TC[] = {
/* set scheduling policy to SCHED_RR */
{
1, SCHED_RR},
{
0, SCHED_OTHER},
{
1, SCHED_FIFO}
{ 1, SCHED_RR},
{ 0, SCHED_OTHER},
{ 1, SCHED_FIFO}
};
int main(int ac, char **av)
int i;
struct sched_param param;
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
}
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
Tst_count = 0;
for (i = 0; i < TST_TOTAL; i++) {
param.sched_priority = TC[i].prio;
if (sched_setscheduler(0, TC[i].policy, ¶m) == -1) {
tst_brkm(TBROK, cleanup, "sched_setscheduler() "
"failed");
}
if (sched_setscheduler(0, TC[i].policy, ¶m) == -1)
tst_brkm(TBROK, cleanup,
"sched_setscheduler failed");
TEST(sched_getscheduler(0));
}
if (STD_FUNCTIONAL_TEST) {
if (TEST_RETURN != TC[i].policy) {
tst_resm(TFAIL, "policy value returned "
"is not correct");
} else {
tst_resm(TPASS, "policy value returned "
"is correct");
}
} else {
if (TEST_RETURN != TC[i].policy)
tst_resm(TFAIL,
"policy value returned is not "
"correct");
else
tst_resm(TPASS,
"policy value returned is correct");
} else
tst_resm(TPASS, "call succeeded");
}
}
}
cleanup();
return -1;
}
tst_exit();
}
void setup()
{
if (geteuid() != 0) {
tst_brkm(TBROK, NULL, "Must run test as root");
}
tst_require_root(NULL);
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
}
void cleanup()
{
TEST_CLEANUP;
}
TEST_CLEANUP;
}
I have the following code....from the previous lab....the above needs to be added to what is...
Explain what the problem is within the program. Fix the problem when you create a child process per column. The code is given below. So basically, after the child processes have successfully excuted their code, the final print statement does not give the correct values. It prints the original matrix rather than the multiplied matrix.#include #include #include #include int main(int argc, char *argv[]){ int row = 0; int column = 0; row = atoi(argv[1]); column = atoi(argv[2]); int *A = ...
operating system programming i need ans and explen after 20 min 2 When we are implementing the following program, then we press "CTRL+C" on the keyboard; that will cause: #include <stdio.h> #include<signal.h> #include <stdlib.h> #include<unistd.h> void handle_sigint (int sig) { } printf("Caught signal $d\n", sig); int main(int argc, char *argv[]) { signal (SIGCONT, handle_sigint); while (1) { printf("the process id is $d \n",getpid()); sleep (1); } return 0; } O print the sentence" Caught signal 2" on the terminal 53,65,67,37,14,98,122,124,183...
GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> // Function ptototypes int readX(); void writeX(int); int main() /// chi read x ---> divi ---> write x into file ---> par read x --> sub--> write x into file---> chi read x-->etc { int pid; // pid: used to keep track of the child process int x = 19530; // x: our value as integer ...
Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you! A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm()...
Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...
Edit the code (shell.c) given to do the tasks asked! will rate for correct answer! Also, include a screen shot of the output and terminal window of each command you used. Read carefully to do this task please. shell.c code given below. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> #include <string.h> int main() { int PID; char lineGot[256]; char *cmd; while (1){ printf("cmd: "); fgets(lineGot, 256, stdin); // Get a string from user (includes \n) cmd = strtok(lineGot, "\n");...
The original code using the gets() function is written below. You need to do (a) change the provided code so that you now use fgets() function to obtain input from the user instead of gets(), (b) make any other necessary changes in the code because of using fgets() function, and (c) fill in the code for the execute() function so that the whole program works as expected (a simple shell program). Note: part c is already done, and the execute...
Directions: use only the signal mechanism system calls don’t use ( wait() or pipe() )in this problem. You can still read/write from/to a file. You must use ( kill() and pause() ) system calls. rewrite code below to do kill and pause system calls #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> // Function ptototypes int readX(); void writeX(int); int main() { int pid; // pid: used to keep track of the child process int x...
Write a program in C using Unix system calls and functions that will change the permissions on a file. The executable shall be called “mychmod” and will be executed by: mychmod -u rwx -g rwx -o rwx -U rwx -G rwx -O rwx file1 file2 ... The lowercase options will add permissions while the uppercase options will remove permissions. Each of the switches is optional and should be interpreted as the ones in the Unix command chmod(1), you can review...
Consider the following function://To compile this code by itself, naturally you need a main method. #include <stdio.h> #include <sys/stat.h> void printFileIndexNumber(char *path){ struct stat statbuf; if (stat(path, &statbuf) == -1) perror("Failed to get file status"); else printf("%s inode number is %d", path, &statbuf.st_ino);} It uses the stat system call to get information about the file indicated by the parameter *path. It puts the information about the file in the structure struct stat statbuf and prints out the file index number/inode...