Hi guys!
I'll simplify my problem.
Guys, I have the following code
Code:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
void read2();
main(int argc, char** argv)
{
int pid,status;
pid=fork();
if ( pid == 0 )
{
read2(argv[1], argv[2]);
You want to play with pipe/fork:#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void work(void) {
int i;
for (i=0; i<512; i++) {
printf("Line %d\n", i);
}
}
int main(void) {
int pfds[2];
pid_t pid;
if (pipe(pfds) < 0) {
perror("pipe failed");
return EXIT_FAILURE;
}
pid = fork();
if (pid < 0) {
perror("fork failed&
I have this code in C but I'm not sure what it does:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main(){
int pid;
int i = 0;
for (i=0;i<3;i++){
printf ("\n\n%d\n\n",i);
pid = fork();
if (pid != 0){
printf("Parent is: %d.\n", getpid());
}
else{
printf("Child is: %d.\n", getpid());
}
}
}
I know it works with
To start off with this is a homework assignment for my Operating Systems course and I am stumped.
The prof wants us to read in a source code file and take out all the comment lines and then output the file back into a new source code file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
fork();
fork();
fork();
puts("hi");
return 0;
}
This program prints 8 times hi and exits,
Why? Is not each fork calls main recursively
as in:
f(): "hi"; f()
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
void prtime() {
time_t rawtime;
struct tm * timeinfo;
char *s;
signal(SIGALRM, prtime);
time ( &rawtime );
timeinfo = localtime ( &rawtime );
alarm (1) ; //printf("Time\n");
printf ( "\033[s\0
Original source code :#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv) {
int max = -1;
int mb = 0;
char* buffer;
if(argc > 1)
max = atoi(argv[1]);
while((buffer=malloc(1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 1024*1024);
mb++;
printf("Allocated %d MB\n&quo
I want to run my C code located in desktop with the header files located in other location. What should be the appropriate gcc command? I have attached the code below.