Jump to content
Sign in to follow this  
e-zdy

Tlg Saya Pasal C Or C++

Recommended Posts

hye leh sesaper bantu saya tak? saya tak pernah ada pengalaman mengune UNIX and tak beberape hebat dlm programming C++ programming C langsung tatau harap member putera dpt bantu saya dlm assignment saya...soklan nye begini

Write two C/C++ programs (UNIX and WINDOWS programs) that create two child processes that are executed sequentially. One is to prints a greeting, sleeps for 20 seconds, and then exit. The other is to display the time and then exit. The parent process should print a greeting before creating the child to display the time. It should then terminate.

The following UNIX and windows command could be used to create process. Fork(), exec(), createprocess().

totally i have no idea ape yg diye nak..so sesaper leh bantu...tq

Share this post


Link to post
Share on other sites

Maknanya dia suruh ko buat satu program parent dan dua program child (terpulang cara teknik apa yg ko nak gunakan).

- salah satu child program tu keluarkan output message greetings, buat la apa2 greetings mengikut kegemaran ko, 'Hello World' ke apa. pastu sleep utk 20 saat dan terminate/exit.

- satu lagi child program buat paparan waktu dan kemudian exit.

Dan pastu ko buat satu parent program yg print greeting pastu display time. pastu terminate. dan ini mesti sequentially, atau consecutively, aku tak tau la perkataan melayu nak cakap camna. btw....Aku harap ko nampak dah idea camna nak buat program parent ni agar matlamat p&p lecturer ko tercapai.

Dia bagi syarat lagi kena guna command Fork(), exec() dan createprocess() dlm membuat application tu.

Dah faham apa yg kena buat? try buat sendiri dulu. Kalau sangkut di mana-mana, paste coding ko di sini, ramai pro di sini boleh tlg tengok-tengokkan.

Edited by electroboy

Share this post


Link to post
Share on other sites

windows platform

process ngan thread lain tau. kalau nak create 2 process baru yg tugasnya berlainan, maknanya u kena buat 3 program laa. satu parent, 2 lagi child tu. agaknya untuk tugas simple camni, guna thread dah memadai.

Share this post


Link to post
Share on other sites

ye tak ye ek.. kena ikut cakap boss walaupun kiter betul smile.gif.

ni yg ringkas.. takde error handler. tambah sendirik :

parent.c

#include <windows.h>

int main() {
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {sizeof(si), 0};
TCHAR szChild1[] = "child1.exe";
TCHAR szChild2[] = "child2.exe";

  CreateProcess(NULL, szChild1, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
  Sleep(1000);
  WaitForSingleObject(pi.hProcess, INFINITE);
  CloseHandle(pi.hProcess);
  CloseHandle(pi.hThread);
  ZeroMemory(&pi, sizeof(pi));
  ZeroMemory(&si, sizeof(si));
  si.cb = sizeof(si);
  printf("PARENT :: Hello\n");
  CreateProcess(NULL, szChild2, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);
  Sleep(1000);
  CloseHandle(pi.hProcess);
  CloseHandle(pi.hThread);
  return 0;
}
child1.c
#include <windows.h>

int main() {
  printf("CHILD 1 :: Hello\n");
  Sleep(20000);
  return 0;
}
child2.c
#include <windows.h>

int main() {
SYSTEMTIME st;
  GetLocalTime(&st);
  printf("CHILD 2 :: Current Time - %.2u:%.2u:%.2u\n", (unsigned int)st.wHour, (unsigned int)st.wMinute, (unsigned int)st.wSecond);
  return 0;
}

edit silap tag daa..

Edited by Ancient One

Share this post


Link to post
Share on other sites

* Topik ini dipindahkan ke C & C++

aaaaaaa tq tq...aku tatau cemane ko leh include window.h....waaa aku blaja tak penah blaja c!! huhu aku rasa cam susah jer nak wat pogemin nie..yg reti flash itu pon sket2...ada tips tk nak asah sket pogemin nie.?? if there is good link...plz plz do plz...gimme biggrin.gif thanks guys...about the linux i just learn it today...waa susah basic c takde...tp main buat je tadi...

Share this post


Link to post
Share on other sites

susahlaaa camni.

mmg susah pon satu bende tak phm pasal c nih...nie file nie nak kene compile buat header file ker? kalau ada yg versi dos rasa lebey senang..sbb c++ pon aku gune dos....win nye tak penah gune...

Share this post


Link to post
Share on other sites

Banyakkan membaca kod orang lain. Cuba sampai dapat, jangan give-up.

Orang yg dah pengalaman kat dalam sini contohnya, semua habiskan masa depan komputer (tengok kod) sampai mata lebam-lebam.

e-zdy punya mata camner? lebam tak? kalau blom lebam, kasi sampai lebam.. heheheh..

Share this post


Link to post
Share on other sites

biasanya compiler yg khusus utk dos takleh compile kod untuk windows. kena carik cross-platform compiler laa.. guna windows nyer C++ compiler bleh laaa..try laa bacer buku pasal C dulu.

Share this post


Link to post
Share on other sites

biasanya yg anda belajar programming c/c++ dalam kelas ialah platform independent dah boleh compile run kat mana2 compiler (kalau ikut standard la)

tapi utk real programming task, platform tertentu banyak mempengaruhi program kita.

cross-platform compiler, biasanya utk digunakan dalam GUI and platform independent task, selebihnya ada code yg berbeza utk platform masing2

http://zephyrous.net/Programming_Windows_B...les_Petzold.chm

http://zephyrous.net/Wrox.Press.-.Beginnin...tion.(2003).chm

Share this post


Link to post
Share on other sites

biasanya yg anda belajar programming c/c++ dalam kelas ialah platform independent dah boleh compile run kat mana2 compiler (kalau ikut standard la)

tapi utk real programming task, platform tertentu banyak mempengaruhi program kita.

cross-platform compiler, biasanya utk digunakan dalam GUI and platform independent task, selebihnya ada code yg berbeza utk platform masing2

http://zephyrous.net/Programming_Windows_B...les_Petzold.chm

http://zephyrous.net/Wrox.Press.-.Beginnin...tion.(2003).chm

kalau gune linux ada sesaper tau tak ape beze diye ngan coding kat ats tu?? aku tk penah pakai linux seumur hidup nie...nak buat program gune linux pon aku tak reti

Share this post


Link to post
Share on other sites

thats what you call API (Application Programming Interface). Windows ader Windows API. Install platform SDK dan u bleh start programming ngan C/C++. Biasanya u akan include windows.h laaa.. Linux.. bergantung laa.. tapi C library memang ader. Function fork() ngan exec() kat atas tu tak silap aku linux nyer syscall. kodnya lain lerr..

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...